Reputation: 415
can any one help me to display set of results in my app in a list view. i got the following
codeList<Result> results = response.results;
for (Result result : results) {
//Toast.makeText(this, result.fromUser, Toast.LENGTH_SHORT).show();
Toast.makeText(this, result.text, Toast.LENGTH_LONG).show();
//String[] ch=getResources().getString(result.text);//result.text;
//adapter = new ArrayAdapter<String>(this,R.layout.mainlist,result.text);
//SimpleArrayAdapter adapter = new SimpleArrayAdapter(this, result.text);
setListAdapter(adapter);
}
i want to show result.text in a listview for each value. i tried everything commented in the code, but not getting. please help me.
Upvotes: 2
Views: 118
Reputation: 2776
with this short snippet of code it is hard to know what the problem might be,
possibly this will help http://developer.android.com/resources/tutorials/views/hello-listview.html
after setListAdapter(adapter);
try adding adapter.notifyDataSetChanged()
or alternatively try adapter.setNotifyOnChange(true)
just after initializing the adapter this might solve your issue if it is what i think it is. else post more of your code
Upvotes: 1
Reputation: 8081
1) extend ArrayAdapter with your custom class:
class MyAdapter extends ArrayAdapter<Result>
2) create xml for layout of each row, eg. row.xml
and set it in constructor of your adapter:
MyAdapter(Activity context, int resourceId, ArrayList<Result>
mResults) {
super(context, R.layout.row, mResults);
}
3) in getView
method of your adapter fill apropriate field with your result.text
4) set list adapter to your custom adapter
MyAdapter adapter = new MyAdapter(this, 0, mResults);
setListAdapter(adapter);
Upvotes: 0