如何将两个 ArrayAdapter 合并为单个 ArrayAdapter
我陷入了在Android中制作ArrayAdapter
的困境...
问题是这样的:
我有两个ArrayAdapter
.. 第一个是男性列表,第二个是女性列表。 我想将它们结合起来,这样它将成为单个 ArrayAdapter,并且我想展示它...
我的朋友建议我应该结合 ArrayList
public ArrayList<String> listOfPeople;
listofPeople = listOfMen;
listCampur.addAll(listOfWomen);
list.SetAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listOfPeople));
是的,看起来很相似。 listOfMen 由男性姓名组成,listOfWomen 由女性姓名组成。
我明白了这个想法,但情况是我想要这些列表的不同布局。 我的意思是我有两个性别图标代表这些列表...... 因此,当列表包含男性时,它会显示男性符号......
那么,如何做到这一点? 有什么建议吗?
I'm stuck in making ArrayAdapter
in Android...
The problem is like this:
I have two ArrayAdapter<String>.
..
The first one, It consist of the list of men, and the second one the list of women..
I want to combine both of them so it will become single ArrayAdapter
and I want to show it...
My friends suggest me that I should combine the ArrayList<String>
which include the list of men and women, for example:
public ArrayList<String> listOfPeople;
listofPeople = listOfMen;
listCampur.addAll(listOfWomen);
list.SetAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listOfPeople));
Yes, it looks similar like that..
listOfMen consist of the men's name and listOfWomen consist of the women's name..
I got that the idea, but the case is I want the different layout of those lists..
I mean I have two gender icons which represents of those lists...
So when the list consist of men, it will show the male symbol for example...
So, how to do this?
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这种情况下,您可以根据位置设置图像。
让我有 5 名男性和 9 名女性的名单
然后我在我的列表中使用了
getView() 方法,我将获得 14 名成员的列表,其中前 5 名是男性,接下来的 9 名是女性,
我可以获取视图的位置,写一个条件 if(position<4) 设置男性图像否则树立女性形象。
另一种选择是使用自定义列表视图
In you case you can set image depending on position.
let i have 5 men and 9 women list
I have used
then in my list i will get list of 14 members out of these first 5 are men and next 9 are women
in getView() method i can get the position of view write a condition if(position<4) set men image otherwise set women image.
Another option is use custom listview