Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am currently in the middle of a project, which involves one Imageview, and one Textview, set up within a custom layout file, and maintained through a custom adapter I have set up.

Everything works fine as it is, the thing is, I would like to have two or even four textviews, and passing in another string array gives me an error. I am a bit stuck here, and will place my code below for you.

The code:

The error:

I am sure it is something rather simple I am doing wrong, but either way it is beyond me.

The error can be seen in the image above. How can I do what I am currently doing, but with 2 TVs?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
145 views
Welcome To Ask or Share your Answers For Others

1 Answer

You need to use the model class below

import java.io.Serializable;

public class ListModel implements Serializable {

    private String name;
    private String address;
    private String image;


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }
}

And in your java class, u need to inflate the data like this

ArrayList<ListModel> arrayList = new ArrayList<>();

for (int i = 0; i <10; i++) {

    ListModel model = new ListModel();

    model.setName("Name " + i);
    model.setAddress("Address " + i);
    model.setImage("Image " + i);

    arrayList.add(model);
}

// YOU CAN USE THIS LIST IN YOUR ADAPTER JUST PASS YOUR ARRAYLIST INTO ADAPTER
CustomCurationAdaptor adapter = new CustomCurationAdaptor(this, arrayList);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...