In my android project I am Using a custom listview to show information. In each element of the listview(Each row in list view) have several clickable forcussable textviews. And I added lstvw.setItemsCanFocus(true), for listview and now i can select any clickable textview and click.
----------------
textviewclick1
textviewclick2
----------------
textviewclick1
textviewclick2
----------------
continue......
But can’t figure out how exactly handle the onClick event for each clickable textview as getView() method in the BaseAdapter class is bit confusing for me.
I implemented onclickListener in the ListviewAdapter class that I extended BaseAdapter and created.
public class ListVWAdapter extends BaseAdapter implements OnClickListener{ implementation...}
can anyone suggest me how to handle onClick(View view) method to handle all the clickable textview items.
I tried following way but did’t work correct. I globally declared the ViewHolder viewholder since I want to access it in this method rather than declaring it in normal way within the getView() method. But initializing normal way by checking if (convertView == null)
@Override
public void onClick(View v) {
if(v==holder.txtViewTitle)
Toast.makeText(v.getContext(), "Link1 : "+ String.valueOf(currentPosition), Toast.LENGTH_LONG).show();
if(v==holder.txtViewDescription)
Toast.makeText(v.getContext(), "Link2 : "+ String.valueOf(currentPosition), Toast.LENGTH_LONG).show();
}
In list item xml, for
<TextView..>setandroid:onClick="onFirstLinkClick". Similarly for second TextView.Then in activity class implement this
Similarly another method for second textview. That should work.