In my app the user presses a button to gain points and they use that score to buy upgrades. In this list view the user buys the upgrades and I want to show the amount of upgrades they've bought.
final ArrayList<HashMap<String, String>> authorList = new ArrayList<>();
//Setup adapter
customListViewAdapter = new CustomListViewAdapter(getApplicationContext(), authorList);
listView.setAdapter(customListViewAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
firstoption = position;
}
});
if (firstoption == 0) {
nigg++;
str = Integer.toString(nigg);
bookPages[firstoption] = str;
}
handler.postDelayed(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 10; i++) {
HashMap<String, String> data = new HashMap<>();
data.put("title", bookTitles[i]);
data.put("pages", bookPages[i]);
data.put("author", authors[i]);
authorList.add(data);
}
handler.postDelayed(this, 1000);
}
}, 1000);
This is the code I have right now, but for some reason it does not update. What am I doing wrong?
CustomListView class
package com.example.navjeevenmann.mytycoon;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.HashMap;
public class CustomListViewAdapter extends BaseAdapter {
private Context mContext;
private ArrayList<HashMap<String, String>> books;
private static LayoutInflater inflater = null;
public CustomListViewAdapter(Context context, ArrayList<HashMap<String, String>> data) {
mContext = context;
books = data;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return books.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (convertView == null) {
view = inflater.inflate(R.layout.program_list, null);
TextView title = (TextView) view.findViewById(R.id.title);
TextView author = (TextView) view.findViewById(R.id.textView);
TextView pages = (TextView) view.findViewById(R.id.pages);
ImageView image = (ImageView) view.findViewById(R.id.list_image);
HashMap<String, String> mBook = new HashMap<>();
title.setText(mBook.get("title"));
author.setText(mBook.get("author"));
pages.setText(mBook.get("pages"));
}
return view;
}
}