Here is my adapter code which currently assigns the values in the DataObject to their respective locations in my layout.xml file. Next, I am trying to add an onclicklistener here which will just print to logcat the only id field that was clicked, rather than the contents of the entire row.
private class DataAdapter extends ArrayAdapter<DataObject> {
private ArrayList<DataObject> items;
public DataAdapter(Context context, int textViewResourceId, ArrayList<DataObject> items) {
super(context, textViewResourceId, items);
this.items = items;
}
@Override
public long getItemId(int arg0) {
return 1;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.data_row, null);
}
DataObject dataObject = items.get(position);
if (dataElement != null) {
TextView field1 = (TextView) view.findViewById(R.id.field1);
TextView field2= (TextView) view.findViewById(R.id.field2);
TextView id = (TextView) view.findViewById(R.id.field_id);
if (field1 != null) {
field1.setText("field1 " + dataOject.getField1);
}
if (field2 != null) {
field2.setText("field2 " + dataOject.getField2);
}
view.setClickable(true);
view.setOnClickListener
// Would like to simply print the id in this method to Log, so that when a row is clicked, only id is printed
}
return view;
}
Thanks for any thoughts or ideas
You can get the value from the underlying datastructure which populates the list.
For example if it is populated from a List and you know the position. Just get the corresponding element from the List
For example i used this code in my project