I am using listview. Each item in the list contains one editor. When I click on edittext, a soft keyboard appears, the edittext that I clicked on quickly gains focus and then loses it. I have to click a second time to really get the focus (why?)
( focus on editext and keyboard up ) Scrolling through the list ...
Since the list items are redesigned, the focus reappears on the edittext in other positions in the list, and I assume that this is normal, BUT why doesnβt Android remove that damn focus ! How can I tell Android in order? I don't want to focus on edittext anymore if my user starts scrolling?
Here is the action code:
public class SimpleList extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.user_picker); ListView listview = (ListView)this.findViewById(R.id.user_picker_list); new UserPickerAdapter(this, listview); }
And adapter code:
public class UserPickerAdapter extends BaseAdapter { private final LayoutInflater mInflater; private String[] mUsers = {"Guib", "Jonas", "Fred", "Denis", "Arnold", "Francois", "David", "Alex", "Saskia", "Verner", "Anatole"}; public UserPickerAdapter(Context context, ListView listview) { mInflater = LayoutInflater.from(context); listview.setAdapter(this); } @Override public int getCount() { return mUsers.length; } @Override public Object getItem(int position) { return mUsers[position]; } @Override public long getItemId(int position) { return position; } static private class Holder { TextView username; } @Override public View getView(int position, View convertView, ViewGroup arg2) { Holder holder; if (convertView != null) { holder = (Holder) convertView.getTag(); } else { holder = new Holder(); convertView = mInflater.inflate(R.layout.user_picker_list_item,null); holder.username = (TextView) convertView.findViewById(R.id.user_picker_list_item_name); convertView.setTag(holder); } String str = (String)getItem(position); holder.username.setText(str); return convertView; }
Just in case, here is the code in 'user_picker.xml'
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical" android:padding="0dp"><ListView android:background="@color/color_grey1" android:cacheColorHint="@color/color_grey1" android:id="@+id/user_picker_list" android:divider="@color/color_blueGrey1" android:layout_height="match_parent" android:layout_width="match_parent"/>
And the one that is in 'user_picker_list_item.xml'
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:orientation="vertical" android:layout_height="fill_parent"><EditText android:layout_height="wrap_content"android:id="@+id/user_picker_list_item_name" android:layout_width="wrap_content" android:minWidth="200dp" android:layout_gravity="center"></EditText></LinearLayout>