I have ListView which I populate with AutoCompleteTextView and EditText. User can add programatically new rows and edit them. However, when I add two or more rows I cannot type inside second/third and so on AutoCompleteTextView - when I touch the TextView the keyboard appears but I can't type anything because it loses focus on AutoCompleteTextView. Here is my adapter getView and xml with design of row.
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if(convertView == null) {
convertView = mInflater.inflate(R.layout.add_meal_activity_list_view_row, null);
holder = new ViewHolder();
holder.productNameTextView = (AutoCompleteTextView) convertView.
findViewById(R.id.mealPartAutoCompleteTextView);
holder.foodQuantityEditText = (EditText) convertView.
findViewById(R.id.mealQuantityEditText);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.foodQuantityEditText
.setText(Utilities.trimDecimalsToString(_mealParts.get(position).foodQuantity));
holder.foodQuantityEditText.addTextChangedListener(new FoodQuantityTextWatcher(position, holder.foodQuantityEditText));
//TODO here fetch real product names from web API
//TODO on item selected - pass to mealPart proudctId of chosen product
ArrayAdapter<String> productNamesAdapter = new ArrayAdapter<String>(_context, android.R.layout.simple_list_item_1, DATA);
holder.productNameTextView.setAdapter(productNamesAdapter);
holder.productNameTextView.addTextChangedListener(new ProductNameTextWatcher(position,holder.productNameTextView));
return convertView;
}
Here is row definition.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="45dp"
android:orientation="horizontal"
android:padding="5dp"
android:focusable="true"
android:focusableInTouchMode="true" >
<AutoCompleteTextView
android:id="@+id/mealPartAutoCompleteTextView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"
android:completionThreshold="2"
android:inputType="textNoSuggestions"
android:textSize="15sp"
style="@style/ListTextView" />
<EditText android:id="@+id/mealQuantityEditText"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:inputType="number"
android:textSize="15sp"
style="@style/ListTextView"
/>
</LinearLayout>
And here is activity in which rows of a list are populated.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
style="@style/ListViewStyle"
android:focusableInTouchMode="true"
android:focusable="true">
<EditText android:id="@+id/mealNameTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/mealNameTextViewHint"
style="@style/TitleTextViewStyle" />
<ListView android:id="@+id/mealPartsListView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<ImageButton
android:id="@+id/okMealButton"
android:layout_width="50dp"
android:layout_height="50dp"
android:gravity="left"
android:src="@drawable/ic_action_accept"
android:contentDescription="@string/addMealPartButtonContentDescription"
android:onClick="onOkMealClick"
android:background="?android:selectableItemBackground"
android:padding="5dp">
</ImageButton>
<ImageButton
android:id="@+id/addMealPartButton"
android:layout_width="50dp"
android:layout_height="50dp"
android:gravity="left"
android:src="@drawable/ic_action_new"
android:contentDescription="@string/addMealPartButtonContentDescription"
android:onClick="onAddMealPartButtonClick"
android:padding="5dp"
android:background="?android:selectableItemBackground">
</ImageButton>
<ImageButton
android:id="@+id/addFavouriteMeal"
android:layout_width="50dp"
android:layout_height="50dp"
android:gravity="left"
android:src="@drawable/ic_action_favorite"
android:contentDescription="@string/addMealPartButtonContentDescription"
android:onClick="onAddMealPartButtonClick"
android:padding="5dp"
android:background="?android:selectableItemBackground">
</ImageButton>
</LinearLayout>
</LinearLayout>
UPDATE
I have looked at LogCat and when I click on AutoComplete that I can't get focus on it logs somethins like this:
01-07 12:35:08.685: E/SpannableStringBuilder(29361): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
This appears to be a Keyboard error for your particular device. See Android - SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
Have you tried testing on the emulator or on other devices?
Additionally, some report that changing the inputType setting has fixed the issue. Try some different options. Since the options for your AutoCompleteTextView are downloaded, you may try setting this field to none:
android:inputType="none"
This is used to answer Android Google Analytics SDK show "SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With