I am trying to get my head round using SimpleAdapter however I am struggling with one item.
How do I return the array of data for the selected view?
Here is the code I use to generate it.
// Data for List Adapter
List<Map<String, Object>> resourceNames = new ArrayList<Map<String, Object>>();
// Make Hashmap of Results Hashmaps
generateData(resourceNames);
//Source information from Hashmap keys (FROM)
String keynames[]={"names","descriptions"};
// Target Views for Data (TO)
int[] targets = new int[] { R.id.textfield_name,R.id.textfield_description};
// Create my Simple Adapter
SimpleAdapter adapter = new SimpleAdapter(this, resourceNames,
R.layout.listrow, keynames,targets
);
setListAdapter(adapter);
}
I then use an onclick listener to get the data using the following code:
setContentView(R.layout.listview);
final ListView listView = getListView();
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
Toast.makeText(arg1.getContext(),
getString(R.string.selected) + " " + position,
Toast.LENGTH_SHORT).show();
// How do I return the entire data that I used
}
});
I can see above how I get the position of the data in the array- but how do I return the actual results data being shown in the view??
Declare
List<Map<String, Object>> resourceNames = new ArrayList<Map<String, Object>>();globally and in ListView’s
onItemClick()just put line,