问题描述
任何一个可以帮助我的显示设置导致我的应用程序的列表视图。我得到了以下
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);
}
我要显示result.text在ListView为每个值。我什么都试过评论在code,但没有得到。请帮助我。
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.
推荐答案
1)扩展ArrayAdapter您的自定义类:
1) extend ArrayAdapter with your custom class:
class MyAdapter extends ArrayAdapter<Result>
2)创建XML的每一行的布局,例如。 row.xml
,并将其设置在适配器的构造:
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)在你的适配器 getView
方法填补apropriate现场与您的result.text
4)集列表适配器的自定义适配器
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);
这篇关于显示字符串时的ListView问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!