Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid custom ArrayAdapter getView method called multiple times - resetting dynamic TextView value
    primarykey
    data
    text
    <p>The getView method in my custom ArrayAdapter is getting called multiple times, which I assume it is meant to. Problem is, I have a quantity TextView which is dynamically set but when you scroll and the box goes off screen the value disappears. I am not sure what I am doing wrong and Google is not proving to be much help. Hopefully someone here can help me.</p> <p>The adapater is called:</p> <pre><code>adapter = new MenuAdapter(thisActivity, R.layout.menu, list); setListAdapter(adapter); </code></pre> <p>My Custom ArrayAdapter:</p> <pre><code>public MenuAdapter(Context context, int textViewResourceId, ArrayList&lt;Object&gt; menu) { super(context, textViewResourceId, menu); this.menu = menu; vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; Object cat = menu.get(position); if (cat.getClass().equals(Category.class)) { v = vi.inflate(R.layout.category, null); Category item = (Category)cat; v.setOnClickListener(null); v.setOnLongClickListener(null); v.setLongClickable(false); TextView tt = (TextView) v.findViewById(R.id.category); tt.setText(item.getName()); } else if (cat.getClass().equals(OrderItem.class)) { v = vi.inflate(R.layout.menu, null); OrderItem orderItem = (OrderItem)cat; Item item = orderItem.getItem(); TextView tt = (TextView) v.findViewById(R.id.title); tt.setText(item.getName()); TextView bt = (TextView) v.findViewById(R.id.desc); bt.setText(item.getDescription()); TextView qty = (TextView) v.findViewById(R.id.qty); qty.setId(item.getId()); ImageButton minus = (ImageButton) v.findViewById(R.id.qtyMinus); minus.setTag(item); ImageButton plus = (ImageButton) v.findViewById(R.id.qtyPlus); plus.setTag(item); } return v; } </code></pre> <p>The menu layout:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="?android:attr/listPreferredItemHeight" android:padding="6dip" android:background="#FFFFFF"&gt; &lt;RelativeLayout android:orientation="vertical" android:layout_width="0dip" android:layout_weight="1" android:layout_height="fill_parent" android:cacheColorHint="#FFFFFF" android:background="#FFFFFF"&gt; &lt;TextView android:id="@+id/title" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center_vertical" android:textSize="16px" android:textColor="#000000" /&gt; &lt;TextView android:id="@+id/desc" android:layout_below="@id/title" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:textSize="11px" android:textStyle="italic" android:textColor="#000000" /&gt; &lt;/RelativeLayout&gt; &lt;ImageButton android:id="@+id/qtyMinus" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/minus" android:paddingTop="15px" android:onClick="minusQty" /&gt; &lt;TextView android:id="@+id/qty" android:layout_width="50px" android:layout_height="50px" android:textColor="#000000" android:textSize="18px" android:gravity="center_vertical|center_horizontal" android:freezesText="true" android:background="@android:drawable/editbox_background"/&gt; &lt;ImageButton android:id="@+id/qtyPlus" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/plus" android:paddingTop="15px" android:onClick="addQty" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>Any help will be greatly appreciated. </p> <p>Many Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload