我在每一行都有listview
一个图像和一个。textview
我想在单击整行时获取文本的值。下面的代码表现得很奇怪。我得到的是随机行的值,而不是单击的值。
我没有得到什么是错的。任何帮助,将不胜感激。
我正在这样做,:
public static class LazyAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader;
public LazyAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.list_row, null);
title = (TextView)vi.findViewById(R.id.title); // title
ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // thumb image
HashMap<String, String> song = new HashMap<String, String>();
song = data.get(position);
// Setting all values in listview
title.setText(song.get(Meida_listActivity.KEY_TITLE));
imageLoader.DisplayImage(song.get(Meida_listActivity.KEY_THUMB_URL), thumb_image);
vi.setOnClickListener( new View.OnClickListener()
{
public void onClick(View v)
{
String listValue = (String) title.getText();
System.out.println("this is value of string ::: :::: " + listValue);
}
});
return vi;
}
}