使用的ListView多次 [英] Using ListView multiple times

查看:122
本文介绍了使用的ListView多次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来编程,所以请解释一下。但我有我脱下parse.com的几个对象。当我得到一个对象,我调用此方法。但我的问题是,每次调用此方法时,它每次更换的第一个项目。我知道这是一个简单的办法,我只是需要一点帮助。

I am new to programming, so please explain. But I have a a few objects I am pulling off of parse.com. When I get an object, I call this method. But my problem is, every time this method is called, it replaces the first item each time. I know this is an easy fix, I just need a bit of help.

private void display(Object name, Object weightClass, Object record, int count) {       


    ListView list = (ListView) findViewById(R.id.list);
    ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
    list.setAdapter(listAdapter);
    String fightCard = (name).toString();
    listAdapter.add(fightCard); 
    listAdapter.notifyDataSetChanged();          
 }

另外,我知道这是另外一个问题完全是,但我知道我需要仰视的方式来定制自己的列表视图,我想改变颜色和大小。有谁知道一些好的链接以了解如何做到这一点?在此先感谢

Also, I know this is another question entirely, but I know I will need to look up ways to customize my list view, I am wanting to change colors and sizes. Does anyone know some good links to learn how to do this? Thanks in advance

推荐答案

考虑改变方法,因此将每次返回一个字符串。
所以这将是:

Consider change the method so it will return each time a String. So it will be :

private String display(Object name, Object weightClass, Object record, int count) {       

String fightCard = (name).toString();
return fightCard;
}

然后中的onCreate():

Then within onCreate() :

ListView lv = (ListView) findViewById(R.id.list);
ArrayList<String> your_array_list = new ArrayList<String>();

 "loop here -> get each String and add it to list : ( your_array_list.add( fightCard ) ) "

        ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);

     lv.setAdapter(arrayAdapter); 

一步一步:

1.在你的布局文件
找到ID声明的列表视图项
2.申报,你会用来存储项目的ArrayList

3.项目添加到您的数组列表。在这里,您从一个方法让他们如此循环,直到你加入他们都

4.声明ArrayAdapter

5.设置您的数据背后的ListView

step by step :
1. declare your listView item by finding the id in your layout file
2. declare an ArrayList you will use to store your items
3. add items to your arraylist. Here you get them from a method so loop until you add them all
4. declare ArrayAdapter
5. set the data behind your listView

这篇关于使用的ListView多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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