Is the TextView price
available in each row of the ListView
?
I suppose the answer is no, like you just have a single TextView on the screen that should display the total price.
If my assumption is right, then you sould not instantiate the price
in the getView()
price = (TextView)v.findViewById(R.id.price);
as the price
will be searched in the R.layout.menuitem_row
layout. If the TextView is not there, NullPointer will be thrown when you'll attempt to use.
The solution would be to instantiate the price
in the onCreate() where your main layout is declared, and then pass it as a parameter to the MenuItemArrayAdapter
.
Something like this:
// ....
TextView price = (TextView)findViewById(R.id.price);
adapter = new MenuItemArrayAdapter(this, price);
this.setAdapter(adapter)
//....
Then modify the constructor of MenuItemArrayAdapter
to accept a TextView:
public MenuItemArrayAdapter(Context context, TextView price){
this.context = context;
this.price=price
}
After that you can use safely price
to update it.