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:
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.
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.
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. getView method for list adapter:
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; }