i am trying to implement list view that has one click-able image View in each row, for this I have created custom Adapter and override all its methods. Now my problem is that
when i click this image view without clicking that row it is not functioning properly my code is below
protected void onListItemClick( ListView l, View v, final int position, long id) {
super.onListItemClick(l, v, position, id);
RowData rowObject = (RowData) l.getItemAtPosition(position);
contactId= rowObject.getTextId();
//contactId gives the position of the row clicked in the list view.
Log.e("on item clicked", contactId.toString());
ImageView nextView = rowObject.getImageobject();
nextView.setClickable(true);
nextView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.i("Value of row id", String.valueOf(position));
Intent myintent = new Intent(v.getContext(),Info.class);
myintent.putExtra("ContactId", contactId);
v.getContext().startActivity(myintent);
}
});
here if i click on the row first and then image view then it is working fine. But if i click on image view without clicking on the row (i.e., without selecting the row), then it takes the position of last row clicked.
please help me.
ok finally digging so much in list view i got a solution by own,and that isthe getView method of custom adaptor,now whenever i click the image View the (int position)argument of getview gives the position of the row that was clicked.here i my code whitch i implemented later.