我有这个数组,我把它作为参数发送到另一个活动, 我如何使用一个数组列表来添加这个项目? 我试图使用数组列表类型模块,但我不能添加所有项目,我不会!
myTextFunc <- function(input, output, session, text) {
ns <- session$ns
output$myFinalText <- renderUI({
output$myText <- renderText({text})
textOutput(ns('myText'))
})
}
答案 0 :(得分:1)
你可以有一个班级
public class Container{
public String[] title;
public String[] desc;
public int[] background ;
public int[] profile;
}
设置属性并通过序列化为字符串将其传递给其他活动。
答案 1 :(得分:0)
按如下方式创建模型类: -
public class Model {
private String title;
private String desc;
private int background;
private int profile;
public Model(String title, String desc, int background, int profile) {
this.title = title;
this.desc = desc;
this.background = background;
this.profile = profile;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public int getBackground() {
return background;
}
public void setBackground(int background) {
this.background = background;
}
public int getProfile() {
return profile;
}
public void setProfile(int profile) {
this.profile = profile;
}
}
然后,当你必须在Arraylist中添加项目时,只需创建一个包含适当项目的模型并按如下方式添加: -
ArrayList<Model> modelList = new ArrayList<>();
Model model1 = new Model("ahmad", "China", R.drawable.apple_ex, R.drawable.apple_ex);
Model model2 = new Model("ali", "India", R.mipmap.ic_launcher, R.drawable.apple_ex);
Model model3 = new Model("omar", "United States", R.mipmap.ic_launcher, R.drawable.apple_ex);
modelList.add(model1);
modelList.add(model2);
modelList.add(model3);
现在你的modelList将拥有你想要的所有值。然后你可以用它来使用forloop获取值
for (Model model : modelList) {
model.getTitle();
model.getDesc();
model.getBackground();
model.getProfile();
}