2

Im using Custom class to fill Adapter on ListView Class looks like that:

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;
    }

}

In my activity Im using this code

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);

Now how to add new items to items array. Finaly I want to fill that items array with data from json data (passed from PHP)

4
  • Parse the JSON response and add it your items Commented Jan 14, 2013 at 21:55
  • You should use an ArrayList instead of an array; you can't dynamically modify an array (it's a fixed size). Commented Jan 14, 2013 at 21:57
  • can you help me out with some code sample? Commented Jan 14, 2013 at 22:32
  • Sry for bumping up, but I realny need to figure it out, how to add new data to items array (for example in FOR iteration), thanks Commented Jan 15, 2013 at 13:14

1 Answer 1

2

I did it, just changed some code to that:

ArrayList<RaidWpis> raid_list = new ArrayList<RaidWpis>();
    raid_list.add(new RaidWpis(1, "aaaa"));
    raid_list.add(new RaidWpis(3, "bbb"));
    raid_list.add(new RaidWpis(5, "ccc"));
    ArrayAdapter<RaidWpis> raidList=new ArrayAdapter<RaidWpis>(this, R.layout.simplerow, raid_list);  

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.