Advertisement
Guest User

Untitled

a guest
Jul 12th, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:paddingBottom="@dimen/activity_vertical_margin"
  6. android:paddingLeft="@dimen/activity_horizontal_margin"
  7. android:paddingRight="@dimen/activity_horizontal_margin"
  8. android:paddingTop="@dimen/activity_vertical_margin"
  9. tools:context=".MainActivity" >
  10.  
  11. <ImageButton
  12. android:id="@+id/imageButton1"
  13. android:layout_width="wrap_content"
  14. android:layout_height="wrap_content"
  15. android:layout_alignRight="@+id/textView1"
  16. android:layout_below="@+id/textView1"
  17. android:layout_marginRight="35dp"
  18. android:layout_marginTop="32dp"
  19. android:contentDescription="image"
  20. android:src="@drawable/ic_launcher" />
  21.  
  22. import android.app.Activity;
  23. import android.os.Bundle;
  24. import android.view.Menu;
  25. import android.view.View;
  26. import android.view.View.OnClickListener;
  27. import android.widget.ImageButton;
  28. import android.widget.Toast;
  29.  
  30. public class MainActivity extends Activity {
  31.  
  32. ImageButton imgButton;
  33.  
  34. @Override
  35. protected void onCreate(Bundle savedInstanceState) {
  36. super.onCreate(savedInstanceState);
  37. setContentView(R.layout.activity_main);
  38.  
  39. addListenerOnButton();
  40. }
  41.  
  42. private void addListenerOnButton() {
  43.  
  44. imgButton = (ImageButton) findViewById(R.id.imageButton1);
  45.  
  46. imgButton.setOnClickListener(new OnClickListener() {
  47. @Override
  48. public void onClick(View view) {
  49. Toast.makeText(MainActivity.this, "Clicked", Toast.LENGTH_SHORT)
  50. .show();
  51. }
  52. });
  53. }
  54. }
  55.  
  56. import android.widget.Toast;
  57.  
  58. public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
  59. View rootView = inflater.inflate(R.layout.your_main_xml_here, container, false);
  60. rootView.findViewById(R.id.user_button_ratings).setOnClickListener(
  61. new View.OnClickListener() {
  62. @Override
  63. public void onClick(View v) {
  64. Toast.makeText(getActivity(),
  65. "Button was clicked", Toast.LENGTH_SHORT).show();
  66.  
  67. }
  68. });
  69.  
  70. return rootView;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement