Reputation: 2445
I have a list view where in there are 2 text view places next to each other. Now, this list will have around more than 100 items in it displaying around 10 items in a single page.
Now, as I scroll down the list for all the positions say from position 12 to how much ever it might be, view returns as null.
When I looked for this, got some results of getFirstVisiblePosition(); etc. How ever, I am not very clear on this.
Could any be able to tell me how can I solve this?
Here is my code,
listview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg,View view, int pos, long arg3) {
View parentView = (View) view.getParent();
parentView = listview.getChildAt(pos);
if (null != parentView) {
TextView dupid, dupdesc;
dupid = ((TextView) parentView.findViewById(R.id.dupitemId));
dupdesc = ((TextView) parentView.findViewById(R.id.dupitemIdDesc));
String duplicateId = dupid.getText().toString();
String duplicateDesc = dupdesc.getText().toString();
}
}
});
When I scroll down say to 20 position,
this line
parentView = listview.getChildAt(pos);
throws me null.
Can any one help me in figuring out?
Upvotes: 0
Views: 439
Reputation: 2702
Isn't this all you need to do?
listview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg,View view, int pos, long arg3) {
TextView dupid, dupdesc;
dupid = ((TextView) view.findViewById(R.id.dupitemId));
dupdesc = ((TextView) view.findViewById(R.id.dupitemIdDesc));
String duplicateId = dupid.getText().toString();
String duplicateDesc = dupdesc.getText().toString();
}
});
Upvotes: 1