UPDATE code is: but when you select 2 edit, the focus returns to 1 edit. I tried to play clearFocus () parameters, but it does not help ..

@Override public View getView(final int position, View convertView, ViewGroup parent) { View view = convertView; if (view == null) { LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = inflater.inflate(R.layout.custom_list_tovar, parent, false); currentPosition = position; holder = new ViewHolder(); holder.title = (TextView) view.findViewById(R.id.title); holder.edit_name_tovar = (Spinner) view.findViewById(R.id.edit_name_tovar); holder.edit_mark_tovar = (EditText) view.findViewById(R.id.edit_mark_tovar); holder.edit_cost_tovar = (EditText) view.findViewById(R.id.edit_cost_tovar); holder.add_button_tovar = (Button) view.findViewById(R.id.add_button_tovar); holder.trash_button = (ImageButton) view.findViewById(R.id.trash_button); view.setTag(holder); } else { holder = (ViewHolder) view.getTag(); } emptyAdapter = new ArrayAdapter<String>(context, R.layout.custom_items_list, R.id.items, list_tov); holder.edit_name_tovar.setAdapter(emptyAdapter); holder.title.setText("Товар_1"); holder.edit_mark_tovar.setOnFocusChangeListener(this); holder.edit_cost_tovar.setOnFocusChangeListener(this); if (holder.edit_mark_tovar.hasFocus()) { holder.edit_mark_tovar.addTextChangedListener(new AddListenerOnTextChange(holder.edit_mark_tovar)); notifyDataSetChanged(); } if (holder.edit_cost_tovar.hasFocus()) { holder.edit_cost_tovar.addTextChangedListener(new AddListenerOnTextChange(holder.edit_cost_tovar)); notifyDataSetChanged(); } //holder.edit_cost_tovar.setMask("dd ddd dd"); return view; } @Override public void onFocusChange(View v, boolean hasFocus) { switch (v.getId()) { case R.id.edit_mark_tovar: //holder.edit_cost_tovar.clearFocus(); if (hasFocus) { handler.postDelayed(new Runnable() { @Override public void run() { if (lastFocussedPosition == -1 || lastFocussedPosition == currentPosition) { lastFocussedPosition = currentPosition; holder.edit_mark_tovar.requestFocus(); } } }, 200); } else { lastFocussedPosition = -1; } break; case R.id.cost_tovar: //holder.edit_mark_tovar.clearFocus(); if (hasFocus) { handler.postDelayed(new Runnable() { @Override public void run() { if (lastFocussedPosition == -1 || lastFocussedPosition == currentPosition) { lastFocussedPosition = currentPosition; holder.edit_cost_tovar.requestFocus(); } } }, 200); } else { lastFocussedPosition = -1; } break; } } 

Listview xml:

 <ListView android:id="@+id/list_tovar" android:layout_width="match_parent" android:layout_height="0dp" android:descendantFocusability="afterDescendants" android:layout_weight=".50"> 

EditText xml:

  <EditText android:id="@+id/edit_cost_tovar" android:hint="Введите сумму" android:focusable="true" android:focusableInTouchMode="true" android:inputType="numberDecimal" style="@style/item_list_tovar"/> 
  • UPDATE: rewrote the code, but the problem is not fully resolved, when using android: descendantFocusability = "afterDescendants", the focus is only on 1 edit, on the second I click, but the focus still returns to 1 edit, and without this parameter, there are 2 click to not get the focus <ListView android: id = "@ + id / list_tovar" android: layout_width = "match_parent" android: layout_height = "0dp" android: descendantFocusability = "afterDescendants" android: layout_weight = ". 50"> - Sergey

1 answer 1

The problem is known, there is such a hack:

  private int lastFocussedPosition = -1; private Handler handler = new Handler(); public View getView(final int position, View convertView, ViewGroup parent) { // ... edittext.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { handler.postDelayed(new Runnable() { @Override public void run() { if (lastFocussedPosition == -1 || lastFocussedPosition == position) { lastFocussedPosition = position; edittext.requestFocus(); } } }, 200); } else { lastFocussedPosition = -1; } } }); return convertView; } 
  • String enter = ((EditText) v) .getText (). ToString (); and so you can pull the data here? It seems like a separate thread? - Sergey
  • The handlers launched via the handler are executed in the thread of a ui - Dmitriy Puchkov
  • can I find out why the value -1 is used? - Sergey
  • Just the default when the position is not set - Dmitriy Puchkov
  • can you tell by update? - Sergey