アダプター リストから関連情報を含むカスタム ダイアログ ボックスを開くように実装しようとしています。ここでは onclicklistener を使用しています。正常に動作しています。カスタム ダイアログ ボックスが表示されます。問題は、正しい情報が得られないことです。ダイアログボックスのリストのアイテムをクリックすると、最後のアイテムの詳細が表示されます。
リストの生成時に、logcat の位置が表示されます。しかし、詳細のテキストビューをクリックしようとすると、最後のアイテムの位置が取られます。
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;
}
}