Android 中嵌入 ListView?
我想在我的程序中使用 listView。但是,我还想在同一窗口中使用一些不同的组件(按钮、文本编辑等)。我该怎么做?
I want to use a listView in my program. However, I also want to use some different components(Button, TextEdit etc.) in the same window. How can i do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为此,您必须使用基本适配器。这很简单。这里面有四个方法
1.获取计数
2.获取项目
3.获取物品ID
4.getView
类CustomListAdapter扩展BaseAdapter
{
然后我们必须创建该类的对象并将该对象设置为:
CustomListAdapter customListAdapter = new CustomListAdapter();
listView.setAdapter(customListAdapter);
上面两行您必须在 onStart 或 onCreate 方法中执行。
我希望这能解决您的问题...只需检查如何创建布局文件,因为必须创建两个布局文件。
You have to use Base Adapter for that. It is simple. There are four methods Inside this
1.getCount
2.getItem
3.getItemId
4.getView
class CustomListAdapter extends BaseAdapter
{
Then we have to create the object of the class and set That Object as:
CustomListAdapter customListAdapter = new CustomListAdapter();
listView.setAdapter(customListAdapter);
Above two lines you have to do inside the onStart or onCreate method.
I hope this will solve your problem...just check how the layout file has to create because their is two layout file has to create.
无需扩展 ListActivity,只需使用常规活动并实例化您的列表视图,如下所示:
您当然必须进行一些自定义,因为这是直接从我自己的应用程序获取的。
我为此应用程序制作了自己的适配器。您可能应该改用 ArrayAdapter。
Instead of extending ListActivity, just use a regular activity and instantiate your list view like this:
You will of course have to do some customization since this is taken directly from my own application.
I made my own adapter for this application. You should probably use an ArrayAdapter instead.