My problem is kind of strange...basically I have a ListView like the one from above :
<ListView
android:id="@+id/listViewMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/order_button"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" >
</ListView>
and for it, i have defined the elements to look like this :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.7">
<TextView android:id="@+id/name"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="#0033CC"
android:layout_marginLeft="10sp"
android:layout_marginTop="5sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView android:id="@+id/price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<EditText
android:id="@+id/quantityEdit"
android:layout_height="85dp"
android:layout_width="85dp"
android:textSize="12sp"
android:textColor="#0033CC"
android:layout_marginRight="15dp"
android:layout_weight="0.3"
android:inputType="number"
android:ems="10"
android:hint="@string/quantity_show">
<requestFocus />
</EditText>
</LinearLayout>
and this is my NEW EDITED addapter
public MyCustomBaseAdapter(Context context, ArrayList<Product> products) {
this.products = products;
this.mInflater = LayoutInflater.from(context);
for (int i=0;i<products.size();i++){
editTextsVlues.add("");
}
}
public int getCount() {
return products.size();
}
public Object getItem(int position) {
return products.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.product_item, null);
holder = new ViewHolder();
holder.quantity = (EditText) convertView.findViewById(R.id.quantityEdit);
holder.picView = (ImageView) convertView.findViewById(R.id.pic_view);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.quantity.setText(editTextsVlues.get(position));
holder.picView.setImageBitmap(products.get(position).getPicture());
positionListener = position;
holder.quantity.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
editTextsVlues.set(positionListener, cs.toString());
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
});
return convertView;
}
}
The problem that I facing is that when i have more elements in the list (they don't fit all in my screen), when i enter a value in a EditText, then another EditText from below is beeing populated...Why is that happening...? I have found no similar cases on the internet .
EDTI: Sam i tried your approach..however my programming skils aren't very good...what do you think is the problem with the adapter now ?...When i enter a value, and lose focus on that edit text, it simply delets it...:(
EDIT2: The tutorial from this website helped me solve my problem : http://vikaskanani.wordpress.com/2011/07/27/android-focusable-edittext-inside-listview/ without using TextWatcher