I’m trying to implement to open a custom dialog box having related info from the adapter list. here I’m using onclicklistener, it is working fine i’m getting custom dialog box, my problem is i’m not getting the correct info. If i click on any item on the list in dialog box it is showing the last item details.
At the time of generating the list it is showing the positions in logcat. But when i’m trying to click on details textview it is taking the last item position.
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View v = convertView;
if(v == null){
LayoutInflater vl = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vl.inflate(R.layout.listItem, null);
}
Fields o = results.get(position);
if (o != null) {
TextView iv = (TextView)v.findViewById(R.id.toptext);
TextView tv_link = (TextView)v.findViewById(R.id.toptext1);
ImageView tv_Image = (ImageView)v.findViewById(R.id.Locimage);
tv_link.setText("Details >>");
tv_link.setOnClickListener( new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Dialog dialog = new Dialog(mContext);
dialog.setContentView(R.layout.locationdetails);
dialog.setTitle("Title");
System.out.println("Position "+pos);
TextView LocName = (TextView) dialog.findViewById(R.id.LocDescName);
LocName.setText(o.getLocationName());
ImageView LocDescImage = (ImageView) dialog.findViewById(R.id.LocDescImage);
Bitmap bitmap;
try {
bitmap = BitmapFactory.decodeStream((InputStream) new URL(o.getLocationImage()).getContent());
LocDescImage .setImageBitmap(bitmap);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
dialog.show();
}
});
}
DbLoc.close();
return v;
}
}
Try to use the setTag(Object o) and getTag() methods on TextView,it may help you
I mean
inside the onClickListener,get that object using v.getTag();
it may solve your problem.