Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
146 views
in Technique[技术] by (71.8m points)

java - Using Multiple Views in a Custom Listview Adapter

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

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

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...