Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You don't have to declare your List static. Here is the code you should have to get it to work (one possibility) :</p> <pre><code>@Override public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) { MyObjectClass obj = (MyObjectClass) arg0.getAdapter().getItem(arg2); Intent intent = new Intent(this, EditActivity.class); intent.putExtra("myKey", obj); startActivity(intent); } </code></pre> <p>This way there is no useless static variables, and you are using the method the way it has been made for. One of the easiest and cleanest solution IMO.<br /> <strong>Be carefull</strong>, to use this method, your have to redefine the <code>getItem(int)</code> method in your custom <code>ArrayAdapter</code>. You should do this :</p> <pre><code>@Override public MyObjectClass getItem(int position) { return this.myList.get(position); } </code></pre> <p><strong>EDIT :</strong> Then if you want to be able to remove items, I think you should put the whole list containing your objects in the intent (don't declare it static). Then just call add()/remove() methods, and when you want to update UI to show the modifed list, just call notifyDataSetChanged() on your custom ArrayAdapter, for example when returning in MainActivity :</p> <pre><code>@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); yourListAdater.notifyDataSetChanged(); /* Assuming you have a reference pointing to your adapter in your MainActivity, if you don't just do: ((MyCustomAdapterClass) myListView.getAdapter()).notifyDataSetChanged(); */ } </code></pre>
    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.
    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