Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to change a value from AlertDialog?
    primarykey
    data
    text
    <p>As long as an <code>EditText</code> with <code>ListView</code> is difficult to figure out, I tried another solution : A <code>ListView</code> with <code>TextViews</code> and when you click on one, I catch the focused <code>TextView</code> with a listener (a <code>OnItemClickListener</code> on the parent <code>ListView</code>) and I open an <code>AlertDialog</code>.</p> <p><strong>ISSUE</strong> : When I press the OK button on the <code>AlertDialog</code>, I want the focused <code>TextView</code> to get the text value of the alert dialog's <code>EditText</code>, but it doesn't work, he keeps the same text value. On activity : </p> <pre><code> listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; a, View v, int pos, long id){ InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0); id ++; t = new TextView(activity); t = (TextView) v; AlertDialog.Builder alert = new AlertDialog.Builder(activity); alert.setTitle("Title"); alert.setMessage("Message"); // Set an EditText view to get user input final EditText input = new EditText(activity); input.setText(t.getText()); alert.setView(input); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //Changer la valeur dans la base et dans la liste InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.HIDE_NOT_ALWAYS,0); t.setText(input.getText()); System.out.println("input avant : " + t.getText()); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Canceled. } }); alert.show(); } }); </code></pre> <p>I think this code is enough for you to know what's wrong in my code. Just to let you know :</p> <ul> <li><code>ListView</code> and <em>t</em> (<code>TextView</code>) are declared as private variables on the activity class</li> <li>there is an <code>Adapter</code> class that builds automatically the <code>TextView</code> list</li> <li>if I change the value of an <code>EditText</code> on the <code>ListView</code> listener, it works, but in the dialog alert listener, it doesn't.</li> </ul> <p>Ask if you want more info.</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.
    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