ListView和ArrayAdapter<串GT; [英] ListView and ArrayAdapter<String>

查看:132
本文介绍了ListView和ArrayAdapter<串GT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这有什么不好这个code?

问题是,测试在的ListView

不显示

Java的:

 私人的ListView namesListView;
私人的ArrayList<串GT;名称;
私人ArrayAdapter<串GT; namesAA;
...
namesListView =(ListView控件)findViewById(R.id.list);
名称=新的ArrayList<串GT;();
names.clear();
names.add(0,测试);
namesAA =新ArrayAdapter<串GT; (这一点,android.R.layout.simple_list_item_1,姓名);
namesListView.setAdapter(namesAA);
...

XML:

 < ListView控件
    机器人:ID =@ + ID /列表
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
/>


解决方案

您是否尝试过这个?

  namesAA =新ArrayAdapter<串GT; (这一点,android.R.layout.simple_list_item_1,android.R.id.text1,姓名);

顺便说一句,你为什么要指定项目的地方吗?你是清除所以加入该ArrayList names.add(测试); 比较好,我觉得

Is there anything bad with this code?

The thing is that the "test" is not displayed in ListView.

Java:

private ListView namesListView;
private ArrayList<String> names;
private ArrayAdapter<String> namesAA;
...
namesListView = (ListView)findViewById(R.id.list);
names = new ArrayList<String>();
names.clear();
names.add(0, "test");
namesAA = new ArrayAdapter<String> ( this, android.R.layout.simple_list_item_1, names );
namesListView.setAdapter(namesAA);
...

XML:

<ListView 
    android:id="@+id/list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
/>

解决方案

Have you tried this?

namesAA = new ArrayAdapter<String> ( this, android.R.layout.simple_list_item_1, android.R.id.text1, names );

By the way, why are you specifying the place of the item? You are clearing the arraylist so adding names.add("test"); is better, I think.

这篇关于ListView和ArrayAdapter&LT;串GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆