Listener code:
lvSearch.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> adapter, View view, int position,
long id) {
LinearLayout ll = (LinearLayout) adapter.getChildAt(position);
TextView tx = (TextView) ll.getChildAt(0);
TextView tx1 = (TextView) ll.getChildAt(1);
Log.i("abcValues", tx.getText().toString());
I am getting a NullPointerException while accessing the item values of a ListView. It is working fine for starting item values but not for items that came after scrolling.
getChildAtreturns the visible rows and as you scroll theLisViewand click the rows you’ll call the methodgetChildAtfor invalid positions(the maximum number you can use with thegetChildAtmethod is the number of visible rows – 1). If you want the parent from the layout of the clicked row, simply use the second parameterarg1in your code: