Wednesday, 21 August 2013

Listview : Getting the text of the selected row

Listview : Getting the text of the selected row

I have a listview with an image and a textview in each row. I want to get
the value of the text on the clicking of the whole row. Below code is
behaving strange.I am getting the value of random row instead of the one
clicked.
I am not getting what is wrong. Any help would be appreciated.
I am doing this, :
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;
}
}

No comments:

Post a Comment