Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. <LinearLayout
  2. xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="wrap_content"
  5. android:orientation="horizontal">
  6.  
  7. <TextView
  8. android:id="@+id/id_icon"
  9. android:layout_width="wrap_content"
  10. android:layout_height="wrap_content"
  11. android:textSize="20sp"/>
  12.  
  13. <TextView
  14. android:id="@+id/name_icon"
  15. android:layout_width="wrap_content"
  16. android:layout_height="wrap_content"
  17. android:textSize="20sp"/>
  18.  
  19. <ImageView
  20. android:id="@+id/del_icon"
  21. android:layout_width="wrap_content"
  22. android:layout_height="wrap_content"
  23. android:src="@android:drawable/ic_delete"
  24. android:layout_gravity="right"/>
  25. </LinearLayout>
  26.  
  27. public class IconAdapter extends BaseAdapter {
  28. Context ctx;
  29. LayoutInflater lInflater;
  30. ArrayList<Icon> objects;
  31.  
  32. public IconAdapter(Context context, ArrayList<Icon> icons) {
  33. ctx = context;
  34. objects = icons;
  35. lInflater = (LayoutInflater) ctx
  36. .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  37. }
  38.  
  39. @Override
  40. public int getCount() {
  41. return objects.size();
  42. }
  43.  
  44. @Override
  45. public Object getItem(int position) {
  46. return objects.get(position);
  47. }
  48.  
  49. @Override
  50. public long getItemId(int position) {
  51. return position;
  52. }
  53.  
  54. @Override
  55. public View getView(int position, View convertView, ViewGroup parent) {
  56. View view = convertView;
  57. if (view == null) {
  58. view = lInflater.inflate(R.layout.item_icon, parent, false);
  59. }
  60.  
  61. Icon p = getProduct(position);
  62.  
  63. ((TextView) view.findViewById(R.id.id_icon)).setText(String.valueOf(p.id));
  64. ((TextView) view.findViewById(R.id.name_icon)).setText(p.name);
  65. return view;
  66. }
  67.  
  68. Icon getProduct(int position) {
  69. return ((Icon) getItem(position));
  70. }
  71.  
  72. ListView lv = new ListView(this);
  73. lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  74. @Override
  75. public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
  76. Log.d("...", "нажат пункт №: " + i + " id: " + l);
  77. }
  78. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement