Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: EditText in ListView issue
    primarykey
    data
    text
    <p>I have a listview in my application that is basically a questionaire so there are some EditTexts that the user needs to fill. I've encountered the following issues:</p> <ol> <li><p>Some of the EditText require numeric input, so I set the inputType in the corresponding xml type as numeric, however, as when I click on the EditText the numeric keyboard is shown but almost immediately it disappears and the regular keyboard is shown.</p></li> <li><p>As you can imagine, I need to store the values that the user inputs in these EditTexts. The problem I have with this is that after I input some text in SOME EditTexts and I scroll down, the text is gone when I go back. You can see in my code that I made an attempt to prevent this and I should mention that it works perfectly fine with checkboxes.</p></li> <li><p>At the beginning I was having problems with losing the focus but I solved it looking at other questions (added descendantFocusablity="beforeDescendants" to the ListView and windowSoftInputMode="adjustPan"). Works fine except that when an EditText is below the half of the screen it loses focus as soon as I start typing into it. <strong>getView method for list adapter:</strong></p> <pre><code>public View getView(final int position,View result,ViewGroup parent) { final ViewHolder vh; final Question question = values.get(position); if(holders[position]==null) vh = new ViewHolder(); else vh = holders[position]; LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); if(question.getQuestionType().equals(Question.TYPE_CLOSED)) { result = inflater.inflate(R.layout.closed_question_list_item, null); vh.cb = (CheckBox)result.findViewById(R.id.checkbox); vh.cb.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { vh.isChecked = isChecked; holders[position] = vh; } }); vh.cb.setChecked(vh.isChecked); } else { result = inflater.inflate(R.layout.numeric_question_list_item, null); vh.et = (EditText)result.findViewById(R.id.question_et); vh.et.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { vh.tvValue = s.toString(); holders[position] = vh; Log.i(TAG,"Entered afterTextChanged for "+ question.getText()); } @Override public void beforeTextChanged(CharSequence s, int start,int count, int after) { } @Override public void onTextChanged(CharSequence s, int start,int before, int count) { } }); vh.et.setText(vh.tvValue); } vh.tv = (TextView)result.findViewById(R.id.question_text); vh.tv.setText(question.getText()); holders[position] = vh; result.setTag(vh); return result; } </code></pre></li> </ol>
    singulars
    1. This table or related slice is empty.
    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.
 

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