0

I have listView with 4 elements ( 2x TextView and 2x button ), What I want to do is disable default onItemClickListener, and set clicklisteners for 2 items in my ListView.

Any idea ?

Thanks in advance!

dejvid
  • 123
  • 1
  • 4
  • 16
  • Ok, this will work but I reached another problem...I have MainFragment where i Have this listView, listView is places in mainfragment_layout, and i also have single_item_layout for each listview item, how could I reach Button which is located in single_item_layout, from my MainFragment in order to set onClickListener for this button ? – dejvid Jul 11 '13 at 12:04
  • here is fragment class: http://pastebin.com/jaD4UWhJ and here is .xml for single item: http://pastebin.com/Qx359dNE, i want to have click listener for ImageView object called: imageSecond ( R.id.imageSecond ) t – dejvid Jul 11 '13 at 12:17
  • okay.. got your problem. You are using `ArrayAdapter`, which is implicit implementation. You should use `BaseAdapter` which is explicit implementation. See my answer at http://stackoverflow.com/questions/17589100/spinner-with-custom-layout-doesnt-show-nothing-android/17589188#17589188 – Chintan Rathod Jul 11 '13 at 12:21
  • so could You tell me what should i do ? – dejvid Jul 11 '13 at 12:32
  • Instead of implementing `ArrayAdapter`, create a new class and extends BaseAdapter or ArrrayAdapter to it. It has `getView` method. Inside that method, you have your views of list items. You can give click events over there. Please visit vogella site. I prefer you to first implement those examples. – Chintan Rathod Jul 11 '13 at 12:40

2 Answers2

1

Use onItemclickListener and if you are using Button or ImageButton (or any UI component which may take the focus from the list item)inside the list item UI, set this field as the following

android:focusable="false"
Ayman Mahgoub
  • 4,152
  • 1
  • 30
  • 27
0

Don't implement onItemclickListener. This will not give you any update of item click. Only register onClick listener to views.

Edit

Reference to use Explicit adapter implementation.

1) http://www.vogella.com/articles/AndroidListView/article.html#listview

Chintan Rathod
  • 25,864
  • 13
  • 83
  • 93
  • 1
    Ok, problem solved. What I did is override getView method in SimpleAdapter. Thanks a lot Chintan Rathod – dejvid Jul 11 '13 at 12:44
  • but theres is one more problem, when i did so, i can't see any data ( strings ) implemented by my SimpleAdapter...i can see only "MediumText". why is that ? – dejvid Jul 11 '13 at 13:00
  • You need to set text over there. This will not automatically assign text to them. So take a reference of text view and set `textview.setText(string)`. – Chintan Rathod Jul 11 '13 at 13:02
  • But the problem is, i'll have there +10 listView items, and each will have different text, date...this must be assigned dynamically. Any idea? – dejvid Jul 11 '13 at 13:03
  • my friend @dejvid, have you seen link i provided? You can create a `Bean` class which has getter/setter method. and create array of that class and set text, date etc. Then dynamically set text to text views. – Chintan Rathod Jul 11 '13 at 13:08