So, my activity implements Runnable and within the run() method I do some web scraping and blah blah blah. But that doesn’t have to do with my question. I want it to run some scraping then update the ListView with the results I get. Inside that run method I have this:
myAL.notifyDataSetChanged();
But it doesn’t seem to be updating my listView… This is my onCreate:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loadingSiteDialog = new ProgressDialog(this);
loadingSiteDialog.setCancelable(false);
loadingSiteDialog.setMessage("Retrieving Data, Please Wait...");
loadingSiteDialog.show();
list = (ListView)findViewById(R.id.list);
myAL = new AdapterList(this,R.layout.mainlistlayout);
list.setAdapter(myAL);
list.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
}
});
loading = true;
this.run();
}
Withing my arrayadapter class I use ArrayLists that I propagate within my run() method.
My Custom ArrayAdapter class:
public class AdapterList extends ArrayAdapter<String>{
public AdapterList(Context context, int textViewResourceId) {
super(context, textViewResourceId);
}
@Override
public View getView(int pos, View convertView, ViewGroup parent){
View v = convertView;
if(v == null){
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.mainlistlayout, null);
}
TextView roomTV = (TextView)findViewById(R.id.roomTV);
roomTV.setText(rooms.get(pos));
TextView wTV = (TextView)findViewById(R.id.washersTV);
wTV.setText(washersAvailable.get(pos) + "/" + washersTotal.get(pos));
TextView dTV = (TextView)findViewById(R.id.dryersTV);
dTV.setText(dryersAvailable.get(pos) + "/" + dryersTotal.get(pos));
Log.i("CSUMB Laundy","Attempting to getView: " + convertView.toString());
return v;
}
}
Am I just forgetting something? Its been a while since I have had to work with custom listviews.
Instead of
Try
Edit:
I guess your listview is not updating because you never add data to your adapter.
Change your adapter class construct method from,
Like:
and get your data with only
and set its contents to your views.
Of course, you should define a class like ListItem and an ArrayList of this class to construct your adapter from this arraylist.
When you stored your data in this arraylist, add it to your adapter.
and it will update your listview.