ListView .putExtra From DB Column
Solution 1:
Try to use setTag:
At first, we set tag:
...
holder.text3.setText(description);
holder.text3.setTag(gotoURL);
And when perform onClick event, get tag:
public void onItemClick(AdapterView<?> a, View v, int position,long id)
{
...
String url = "";
if(v != null) {
TextView tv = (TextView)arg1.findViewById(R.id.caption);
url = (String) tv.getTag();
}
i.putExtra("url", url);
startActivity(i);
}
Solution 2:
In OnItemClickListener.onItemClick
method, there is an id
arguments, while you are using SimpleCursorAdapter
, the id, which is _ID
column in sqlite database, of selected item will be passed to the id
argument, so you can get the selected column from DB with this id
value.
Following is the sample code, hope it can help.
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Cursor c = queryById(id);
// Get the url from DB.
String url = c.getString("url");
}
Solution 3:
The reason you're pulling data from the wrong row is because you're handling the convertView
parameter incorrectly. You're only ever setting the holder
to point at the very first set of TextView
objects you set up. I think that your holder
concept is unnecessary. Lose that, set text fields explicitly each time, use the Cursor
as I mentioned in your previous question.
Post a Comment for "ListView .putExtra From DB Column"