Note that there are some explanatory texts on larger screens.

plurals
  1. POSpecific OnItemClick Intent Android
    primarykey
    data
    text
    <p>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. </p> <p>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.</p> <p>As of now, I have the following code snippet :</p> <pre><code> //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&lt;?&gt; 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); } </code></pre> <p>// <strong>EDIT :ADD ITEM CODE ADDED</strong></p> <pre><code>private void addItem() { HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); map.put("row_1", row1); map.put("row_2", row2); painItems.add(map); adapter.notifyDataSetChanged(); } </code></pre> <p>//*<em>EDIT: some defining *</em></p> <pre><code>SimpleAdapter adapter; List&lt;HashMap&lt;String, String&gt;&gt; painItems = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); </code></pre> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload