所属分类列表视图 [英] Categorise the listview

查看:159
本文介绍了所属分类列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的用我的Andr​​oid应用程序并加载数据的列表视图,从数据库

I am using a list view in my android application and loads data from database using

setListAdapter(adapter);

现在我想根据该数据,得到对每个项目的左侧的彩色条在列表中。我该怎么办呢?请帮我。

Now I want to give the colored bars on the left side of each item in the list according to the data. How can I do it? Please help me.

我的想法是创建一个列表视图,如图所示。

My idea is to create a list view as shown in the figure.

在此先感谢...

推荐答案

如果你还没有,你需要编写自定义ListAdapter,
http://developer.android.com/reference/android/widget/ListAdapter.html

if you have not, you need to write a custom ListAdapter, http://developer.android.com/reference/android/widget/ListAdapter.html

您将通过扩大BaseAdapter开始,
http://developer.android.com/reference/android/widget/BaseAdapter.html

you will start by extending BaseAdapter, http://developer.android.com/reference/android/widget/BaseAdapter.html

和最终覆盖getView()。这就是你将构建您的自定义视图。在XML定义它,它充气,并设置在左边的图像视图到任何你想要基于这一立场支持视图的模型元素的状态。

and will ultimately override getView(). that's where you will construct your custom view. define it in XML, inflate it, and set the image view on the left to whatever you want based on the state of the model element for that position backing the view.

创建一个自定义列表适配器的细节超出了什么,我可以写在这里的范围,但如果你在谷歌它可以,你可以找到很多很好的例子。这里有一个,涵盖了基础知识,
<一href=\"http://androidcookbook.com/Recipe.seam;jsessionid=5424397F3130CE7769FF47DD67742911?recipeId=588&recipeFrom=ViewTOC\" rel=\"nofollow\">http://androidcookbook.com/Recipe.seam;jsessionid=5424397F3130CE7769FF47DD67742911?recipeId=588&recipeFrom=ViewTOC

the details of creating a custom list adapter are beyond the scope of what i can write here, but if you google on it can you can find lots of good example. here's one that covers the basics, http://androidcookbook.com/Recipe.seam;jsessionid=5424397F3130CE7769FF47DD67742911?recipeId=588&recipeFrom=ViewTOC

这篇关于所属分类列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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