Note that there are some explanatory texts on larger screens.

plurals
  1. POlistview item button change text
    primarykey
    data
    text
    <p>How is it possible to change text in a textview from a listview item. I got a productAdapter and now i try to add a onclicklistener for the items. I got 2 buttons in my listview items when i click them the text should change. The onclicklistener works btw i outprintet the position of the clicked item that worked.</p> <pre><code>public class ProductAdapter extends ArrayAdapter&lt;Product&gt;{ Context context; int layoutResourceId; List&lt;Product&gt; data = null; public ProductAdapter(Context context, int layoutResourceId, List&lt;Product&gt; yal) { super(context, layoutResourceId, yal); this.layoutResourceId = layoutResourceId; this.context = context; this.data = yal; } @Override public View getView(int position, View convertView, ViewGroup parent) { View row = convertView; prodHolder holder = null; final int pos=position; if(row == null) { LayoutInflater inflater = ((Activity)context).getLayoutInflater(); row = inflater.inflate(layoutResourceId, parent, false); holder = new prodHolder(); holder.imgIcon = (ImageView)row.findViewById(R.id.imgIcon); holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle); holder.txtPrice = (TextView)row.findViewById(R.id.txtPrice); holder.txtAmount = (TextView)row.findViewById(R.id.txtAmount); holder.minus = (Button)row.findViewById(R.id.minbtn); holder.plus = (Button)row.findViewById(R.id.plusbtn); row.setTag(holder); } else { holder = (prodHolder)row.getTag(); } holder.minus.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { onMinButtonClicked(pos,prod,v); } }); holder.plus.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { onPlusButtonClicked(pos,prod,v); } }); return row; } private void onMinButtonClicked(int position,Product prod,View row) { short am= prod.getAmount(); if(am&gt;0){ am=(short) (am-1); } prod.setAmount(am); SerializeIt si=new SerializeIt(); si.storeMyData(prod,context); } private void onPlusButtonClicked(int position,Product prod,View row) { short tt=(short) (prod.getAmount()+1); prod.setAmount(tt); SerializeIt si=new SerializeIt(); si.storeMyData(prod,context); } static class prodHolder { ImageView imgIcon; TextView txtTitle; TextView txtPrice; TextView txtAmount; Button minus; Button plus; } } </code></pre> <p>Hopefully some can help me :)</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.
    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