0

Lately I have been working on my Shopping App. It's used commercially in the AppStore. So a few of users asked for a function to directly add an article price and finally a total price of all list items. So I tried to realise this in my app.

So I have build my listview

items = new ArrayList<String>();
adapter = new ArrayAdapter(this, R.layout.item_layout, R.id.txt, items);
listView.setAdapter(adapter);

And my listview works super. Now I want to get the position of an item in the ListView.

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {

            String value = (String)adapter.getItem(position);
            Toast.makeText(getApplicationContext(), value, Toast.LENGTH_LONG).show();
        }
    });

So and now I want to add a function to override my listview item and set a new 'Price'.

And last but not least my question. How can i get a total of all prices in the ListView?

I mean (Position 1 1,99), (Position 2 1,05), (Position 3 4,50), (Total 7,54),

Thx for all of your help :D

Dennis van Opstal
  • 1,294
  • 1
  • 22
  • 44
Lyan
  • 23
  • 3
  • are you using custom adapter? if no, u need to use custom adapter to achieve your requirement. example [link](http://stackoverflow.com/questions/8166497/custom-adapter-for-list-view) – Manikanta Ottiprolu May 25 '16 at 14:10

1 Answers1

0

Rather than items = new ArrayList<String>();, you should have a class Item with item's name and price

Nguyen Quang Anh
  • 315
  • 1
  • 3
  • 12