I am trying to get data from a db column that contains an URL link; The column name is 'goto' w/in the db. I need to pass this into my onItemClick Intent in my ListView to load a webpage into the new/next Activity.
I don't know how to get this to function. If you can please show code modifications with an explanation, this would be very helpful to me learning. Thnx!
REVISED:
I am now getting data passed but my method is returning the wrong row ID. I revised the below Activity. Any help Plz. THNX
Within my Activities .onCreate (REVISED):
final ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
// @Override
public void onItemClick(AdapterView<?> a, View v, int position,long id)
{
Object o = lv.getSelectedItem();
//Adapter_AC fullObject = (Adapter_AC)o;
String url = "gotoURL";
if(v != null) {
TextView tv = (TextView)lv.findViewById(R.id.dummy);
url = (String) tv.getTag();
}
Toast.makeText(List_AC.this, "Clicked: " + url, Toast.LENGTH_LONG).show();
Intent i = new Intent(List_AC.this, DocView.class);
i.putExtra("url", url);
startActivity(i);
}
});
My Adapter:
public class Adapter_AC extends SimpleCursorAdapter {
private Cursor dataCursor;
private LayoutInflater mInflater;
public Adapter_AC(Context context, int layout, Cursor dataCursor,
String[] from, int[] to) {
super(context, layout, dataCursor, from, to);
this.dataCursor = dataCursor;
mInflater = LayoutInflater.from(context);
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.list_item, null);
holder = new ViewHolder();
holder.text1 = (TextView) convertView.findViewById(R.id.label);
holder.text2 = (TextView) convertView.findViewById(R.id.listTitle);
holder.text3 = (TextView) convertView.findViewById(R.id.caption);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
dataCursor.moveToPosition(position);
int label_index = dataCursor.getColumnIndex("label");
String label = dataCursor.getString(label_index);
int title_index = dataCursor.getColumnIndex("title");
String title = dataCursor.getString(title_index);
int description_index = dataCursor.getColumnIndex("description");
String description = dataCursor.getString(description_index);
int goto_index = dataCursor.getColumnIndex("goto");
String gotoURL = dataCursor.getString(goto_index);
holder.text1.setText(label);
holder.text2.setText(title);
holder.text3.setText(description);
return convertView;
}
static class ViewHolder {
TextView text1;
TextView text2;
TextView text3;
}
}