• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Listview with custom adaptor help

amck77

Lurker
Oct 31, 2014
2
0
Hello, this is my first post as I have not long started Android app development.

I was hoping for some advice on the app I am messing about with at the moment. There might be a better way which I have not come across so it would be really good if anyone could point me in the right direction.

I am basically wanting a list with a title, sub title, a picture and a quantity in each row. At the bottom of the screen are two buttons, Increment and Decrement. They manipulate the quantity number for the currently selected row.

I have got my app to the point where that works but does not change the quantity value displayed in the selected row. Only the variable value which I show on the screen temporarily with a Toast. This is where I have got stuck for some time.

I am not sure what to search for anymore and hope someone could give me a bit of information on what I could try or maybe just say I have gone about the whole thing in the wrong way. Incidentally, I am using a listview with a custom adaptor and fill the list initially with an array.

Any suggestions would be brilliant!
 
Hi BitGriff, here is my adaptor code. Its a bit of a jumble as I have followed various tutorials to get to where I am. Let me know if any other bits of my code will help.


public class BulbChooserAdaptor extends ArrayAdapter<BulbInfo> {

Context context;
int layoutResourceID;
BulbInfo bulbs[] = null;


public BulbChooserAdaptor(Context context, int layoutResourceID, BulbInfo[] bulbs) {
super(context, layoutResourceID, bulbs);
this.layoutResourceID = layoutResourceID;
this.context =context;
this.bulbs = bulbs;
}


@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
BulbHolder holder = null;

if(row == null) {
//Create new view
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceID, parent, false);

holder = new BulbHolder();
holder.imgIcon = (ImageView)row.findViewById(R.id.imgIcon);
holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle);
holder.txtSubTitle = (TextView)row.findViewById(R.id.txtSubTitle);
holder.txtQuantity = (TextView)row.findViewById(R.id.txtQuantity);

row.setTag(holder);
//Area above for properties that are all the same.
}
else
{
holder = (BulbHolder)row.getTag();
}

BulbInfo currentRowItem = getItem(position);


//This area is for properties that are different
final BulbInfo bulbinfo = bulbs[position];
holder.txtTitle.setText(bulbinfo.title);
holder.imgIcon.setImageResource(bulbinfo.icon);
holder.txtSubTitle.setText(bulbinfo.subTitle);
holder.txtQuantity.setText(Integer.toString(bulbinfo.quantity));


return row;
}


static class BulbHolder
{
ImageView imgIcon;
TextView txtTitle;
TextView txtSubTitle;
TextView txtQuantity;
}



}
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones