I use a listview. Each item in the list contains one edittext. When I click on an edittext, the soft keyboard pops up, the edittext I clicked on gains the focus for a short time and then lose it. I have to click a second time to really get the focus (why?)
(focus on an editext and keyboard up) I scroll the listview...
Because the listview elements are recycled, the focus reappears on edittext at other positions in the list and I guess this is normal BUT why does Android not remove this damned focus!? How could I say to Android ok I do not want the focus anymore on an edittext if my user begins to scroll ?
Here is the code of the activity:
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 the code of the adapter:
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 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>