I want the following to happen (a simple idea): I click an Add button in my main activity, enter some info(into EditText boxes), and go back to the main screen. Here, I want to display a list, with just two titles(not all the info). When I click that list Item, I want to show the corresponding saved info for that item. Therefore, each item's info is going to be different.
When I do this, I use startActivityForResult() from the main screen then back. This works perfectly for one item. When I add another item, the problem arises. No matter which item I click, the info displayed is the same. In short, I need to find a way to save that info unique to each item.
As of now, I have the following code snippet :
//After I add all the information in the second intent
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == 1) {
//these display in the list (Each list item has two textfields,row1 and row 2)
row1 = data.getStringExtra("com.painLogger.row1");
row2 = data.getStringExtra("com.painLogger.row2");
//below is the other info entered
painLevelString = data.getStringExtra("com.painLogger.painLevel");
painLocation = data.getStringExtra("painLocation");
timeOfPainString = data.getStringExtra("com.painLogger.painTime");
textTreatmentString = data
.getStringExtra("com.painLogger.treatment");
addItem();
}
}
//When I click the item-- this is the info that is not unique...
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Intent intent = new Intent(this, Item1.class);
intent.putExtra("com.painLogger.painLevel", painLevelString);
intent.putExtra("com.painLogger.painTime" , timeOfPainString);
intent.putExtra("com.painLogger.treatment", textTreatmentString);
intent.putExtra("painLocation", painLocation);
startActivity(intent);
}
// EDIT :ADD ITEM CODE ADDED
private void addItem() {
HashMap<String, String> map = new HashMap<String, String>();
map.put("row_1", row1);
map.put("row_2", row2);
painItems.add(map);
adapter.notifyDataSetChanged();
}
//*EDIT: some defining *
SimpleAdapter adapter;
List<HashMap<String, String>> painItems = new ArrayList<HashMap<String, String>>();
I can understand why this is occuring-- every time I click an item, the intent is putting the last extra, meaning the last object's info added. How do I make each OnItemClick unique? I suspect I will have to use the position variable.