使用arrayadapter Android动态添加项目到listview

时间:2013-01-14 21:51:56

标签: android listview android-arrayadapter

我使用Custom类在ListView上填充Adapter 类看起来像这样:

package com.example.raidplanner;

public class RaidWpis {
    private int id;
    private int id_gildia;
    private String nazwa;
    private int schemat;
    private int data_zapis;
    private int data_start;
    private int opis;
    private int id_officer;
    private int nick_officer;
    private int typ;

    public RaidWpis(int id,String nazwa) {
        setNazwa(nazwa);
        setId(id);
    }

    public int getId(){
        return id; 
    }       

    public void setId(int id){
        this.id = id; 
    }

    public String getNazwa() {
        return nazwa;}

    public void setNazwa(String nazwa) {
        this.nazwa = nazwa;
    }

    public String toString() {
        return this.nazwa;
    }
    public String toString2() {
        return this.id+" - "+nazwa;
    }

}

在我的活动中使用此代码

RaidWpis[] items = {
    new RaidWpis(1, "aaaa"),
    new RaidWpis(3, "bbbb"),
    new RaidWpis(6, "cccc"),
    new RaidWpis(11, "dddd"),
    new RaidWpis(17, "eeee"),
};

mainListView = (ListView) findViewById( R.id.mainListView );

ArrayAdapter<RaidWpis> raidList = new ArrayAdapter<RaidWpis>(this, R.layout.simplerow, items);

// Create ArrayAdapter using the raid list.
mainListView.setAdapter(raidList);

现在如何向items数组添加新项目。最后我想用json数据(从PHP传递)中的数据填充该items数组

0 个答案:

没有答案