Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot Retrieve Value of a Dynamically created EditText
    primarykey
    data
    text
    <p>Hi Guys I created some EditTexts dynamically from a JSON with a default value.</p> <p>After entering some values to the EditTexts I accessed them using the <strong>getChildAt()</strong> method of the root view. When using the <strong>getText()</strong> method of the EditText it returned the default value, not the changed value. I could not even set the text of the EditText through code.</p> <p>This is my method for creating the EditText.</p> <pre><code>private static EditText createEditText(final Context context, Element element) { final EditText editText = new EditText(context); editText.setId(Integer.parseInt(element.getFieldID())); editText.setText(element.getCellValue()); editText.setTag(element); editText.setOnEditorActionListener(new TextView.OnEditorActionListener() { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (event != null &amp;&amp; (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) { InputMethodManager inputMethodManager = (InputMethodManager) context .getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow( editText.getApplicationWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } return false; } }); return editText; } </code></pre> <p>And this is how I access the EditTexts after changing the text.</p> <pre><code>public static boolean updateElements(ScrollView rootView) { try { for (int i = 0; i &lt; rootView.getChildCount(); i++) { View view = rootView.getChildAt(i); if (view.getClass() == LinearLayout.class) { LinearLayout layout = (LinearLayout) view; for (int x = 0; x &lt; layout.getChildCount(); x++) { View linearView = layout.getChildAt(x); if (linearView.getClass() == EditText.class) { EditText txtBox = (EditText) linearView; txtBox.setText("TextBox " + x); } } } } } return true; } catch (Exception ex) { ex.printStackTrace(); return false; } } </code></pre> <p>Please tell me what I'm doing wrong here... Thank You.</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.
 

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