Reputation: 1116
I have a ListView with Checkboxes, (TextView+Checkboxes) and I did the setOnLongClickListener for the items itself:
view = inflator.inflate(R.layout.rowbuttonlayout, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) view.findViewById(R.id.label);
viewHolder.text.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View arg0) {
Viewholder comes from my custom adapter to my Listview, no need to specify details I guess. This works pretty good, problem is: if I try to to the same just with setOnItemClickLister (I just want to do a "small" click) I get the error:
The method setOnItemClickListener(new OnItemClickListener(){}) is undefined for the type TextView
Tried this way:
viewHolder.text.setOnItemClickListener(new OnItemClickListener() {
and
viewHolder.text.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener(){
But I always get that error. What can I do ?
Upvotes: 0
Views: 1050
Reputation: 848
You are casting your "text" argument to a "TextView". This Class has by definition no items. So there will never be a "OnItemClick" event. You want do define this behavior on your ListView, not on your text inside the items.
Example:
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
...
}
);
In your case you want to act on what you described as "...my Listview...". On the other hand, if you realy want to act on the TextView inside your item, then you should implement the "setOnClickListener" method for your TextView.
Example:
viewHolder.text.setOnClickListener(new OnClickListener(){
...
}
);
Upvotes: 0
Reputation: 6575
I think you need a plain OnClickListener instead of an OnItemClickListener
viewHolder.text.setOnClickListener(new OnClickListener() {
Upvotes: 3