Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get a local variable value from onItemClickListener to use it on another activity?
    primarykey
    data
    text
    <p>I have a listview populated from database and on onItemLongClick I have a context menu which I want to use it to edit and update the selected item of list. The problem is that I don' t know how to get the selected item' s values so to use them on another activity which has a form with edittexts. I want when the new activity starts, these string values to be on the apporopriate edittexts. Here is the onItemLongClick code:</p> <pre><code> **REMOVED AND ADDED CORRECT CODE BELOW** </code></pre> <p>With the cursor I get the selected item's values and store them on Strings nameOfSong and artistOfSong. How can I achive when the activity starts to be filled the respective edittexts?</p> <p><strong>==EDIT==</strong> I used SharedPreferences in this way which works:</p> <p>OnItemLongClick of first activity:</p> <pre><code>public boolean onItemLongClick(AdapterView&lt;?&gt; listview, View arg1, final int position, final long arg3) { //bind context menu to listview' s onIitemLongClick(touch and hold) // Get the cursor, positioned to the corresponding row in the result set Cursor cursor = (Cursor) listview.getItemAtPosition(position); // Get the state's capital from this row in the database. registerForContextMenu(listView); openContextMenu(listView); String nameOfSong = cursor.getString(cursor.getColumnIndexOrThrow("songname")); String artistOfSong = cursor.getString(cursor.getColumnIndexOrThrow("artist")); SharedPreferences.Editor editor = prefs.edit(); editor.putString("key1", nameOfSong); editor.putString("key2", artistOfSong); editor.commit(); </code></pre> <p>second activity code:</p> <pre><code>public void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.update_item); etEditSong = (EditText) findViewById(R.id.etEditSong); etEditArtist = (EditText) findViewById(R.id.etEditArtist); sEditDance = (Spinner) findViewById(R.id.sUpdDanceList); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); etEditSong.setText(prefs.getString("key1", null)); etEditArtist.setText(prefs.getString("key2", null)); } </code></pre> <p>Now I'm getting the strings on second activity. Now need to find how to update the database row from above editTexts values.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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