I’m having a ListView. Each row of ListView contains 2 TextView.
I have implemented setOnItemClickListener for ListView as following:
list.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// String item = list.getItemAtPosition(position).toString();
TextView item =(TextView)list.getItemAtPosition(position);
}});
but it gives me ‘ClassCastException’ as following:
java.lang.ClassCastException: java.lang.Integer
at com.idealake.lic.Activities.PlansActivity$1.onItemClick(PlansActivity.java:62)
at android.widget.AdapterView.performItemClick(AdapterView.java:284)
at android.widget.ListView.performItemClick(ListView.java:3513)
My doubts are:
- How can I retrieve content of the
TextViewpresent withinListViewrow. - How do I differentiate between 1st
TextViewand 2ndTextView, while retrieving data?
Any help appreciated.
Use findViewbyId()
Instead of,
try this,
In case if you find this to be not working then just try it with your view object like this,
Bcoz on a ItemCLick Listener, you will be provided with the exact element from the view which you are trying to reference. So you need not use position here once again to find your TextView.