Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. <ImageView android:layout_width="wrap_content"
  2. android:layout_height="wrap_content"
  3. android:src="@drawable/arrow"
  4. android:layout_alignParentRight="true"
  5. android:onClick="btnclick"
  6. android:layout_centerVertical="true"/>
  7. How can I make this to be different, like ItemClickListener with position?
  8.  
  9. class DAdapter extends ArrayAdapter<String>{
  10. Context context;
  11. int [] images;
  12. String[] titleArray;
  13. DAdapter(Context c, String [] titles, int imgs[])
  14.  
  15. {
  16. super(c,R.layout.single_row, R.id.title,titles);
  17. this.context=c;
  18. this.images=imgs;
  19. this.titleArray=titles;
  20. }
  21.  
  22.  
  23. @Override
  24. public View getView(int position, View convertView, ViewGroup parent) {
  25. View row=convertView;
  26. if (row==null) { LayoutInflater inflater= (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  27. row=inflater.inflate(R.layout.single_row, parent,false);
  28. }
  29. ImageView myImage=(ImageView) row.findViewById(R.id.list_image);
  30. TextView myTitle=(TextView) row.findViewById(R.id.title);
  31.  
  32.  
  33.  
  34. myImage.setImageResource(images[position]);
  35. myTitle.setText(titleArray[position]);
  36.  
  37. return row;
  38.  
  39. <RelativeLayout
  40. xmlns:android="http://schemas.android.com/apk/res/android"
  41. android:layout_width="fill_parent"
  42. android:layout_height="wrap_content"
  43. android:background="@drawable/list_selector"
  44. android:orientation="horizontal"
  45. android:padding="5dip" >
  46.  
  47. <LinearLayout android:id="@+id/thumbnail"
  48. android:layout_width="wrap_content"
  49. android:layout_height="wrap_content"
  50. android:padding="3dip"
  51. android:layout_alignParentLeft="true"
  52. android:background="@drawable/image_bg"
  53. android:layout_marginRight="5dip">
  54.  
  55. <ImageView
  56. android:id="@+id/list_image"
  57. android:layout_width="50dip"
  58. android:layout_height="50dip"
  59. android:src="@drawable/ic_launcher"/>
  60.  
  61. </LinearLayout>
  62.  
  63. <TextView
  64. android:id="@+id/title"
  65. android:layout_width="wrap_content"
  66. android:layout_height="wrap_content"
  67. android:layout_alignTop="@+id/thumbnail"
  68. android:layout_toRightOf="@+id/thumbnail"
  69. android:text=""
  70. android:textColor="#040404"
  71. android:typeface="sans"
  72. android:textSize="15sp"
  73. android:textStyle="bold"/>
  74.  
  75.  
  76. <ImageView android:layout_width="wrap_content"
  77. android:layout_height="wrap_content"
  78. android:src="@drawable/arrow"
  79. android:layout_alignParentRight="true"
  80. android:onClick="btnclick"
  81. android:layout_centerVertical="true"/>
  82.  
  83. </RelativeLayout>
  84.  
  85. <ImageView android:layout_width="wrap_content"
  86. android:layout_height="wrap_content"
  87. android:src="@drawable/arrow"
  88. android:layout_alignParentRight="true"
  89. android:id="@+id/arrowImage"
  90. android:onClick="btnclick"
  91. android:layout_centerVertical="true"/>
  92.  
  93. @Override
  94. public View getView(int position, View convertView, ViewGroup parent) {
  95. View row = convertView;
  96. if (row == null) {
  97. LayoutInflater inflater = (LayoutInflater) context
  98. .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  99. row = inflater.inflate(R.layout.single_row, parent, false);
  100. }
  101. ImageView myImage = (ImageView) row.findViewById(R.id.list_image);
  102. TextView myTitle = (TextView) row.findViewById(R.id.title);
  103. myImage.setImageResource(images[position]);
  104. myTitle.setText(titleArray[position]);
  105. ImageView arrowImage = (ImageView) row.findViewById(R.id.arrowImage);
  106. arrowImage.setTag(position);
  107. arrowImage.setOnClickListener(new OnClickListener() {
  108.  
  109. @Override
  110. public void onClick(View v) {
  111. int clickedposition=(Integer) v.getTag();
  112. //Write your Activity launch code here..
  113. }
  114. });
  115. return row;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement