我是关于android编程的新手,今天我想将数据添加到另一个模型类
并且在另一个类模型中是相同的模型
但我不知道添加它
例如
我的第一个模特
public class TelephoneModel {
private List<DataBean> data;
public List<DataBean> getData() {
return data;
}
public void setData(List<DataBean> data) {
this.data = data;
}
public static class DataBean {
private String id;
private String name;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
和我的第二个模特
public class TelephoneDetailModel {
private List<DataBean> data;
public List<DataBean> getData() {
return data;
}
public void setData(List<DataBean> data) {
this.data = data;
}
public static class DataBean {
private String id;
private String name;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
我在
中有数据List<TelephoneModel.DataBean> databeans = new ArrayList<>;
List<TelephoneDetailModel.DataBean> dataDetailbeans = new ArrayList<>;
我希望将数据databeans
添加到dataDetailbeans
如何添加,请为我举例,
谢谢!
答案 0 :(得分:3)
- 试试这个
List<TelephoneDetailModel.DataBean> databeans = new ArrayList();
TelephoneDetailModel.DataBean dataBean = new TelephoneDetailModel.DataBean();
dataBean.setId("1");
dataBean.setName("PREM");
databeans.add(dataBean);
TelephoneDetailModel.DataBean model1 = new TelephoneDetailModel.DataBean();
model1.setId("2");
model1.setName("PREM2");
databeans.add(model1);
TelephoneDetailModel.DataBean model2 = new TelephoneDetailModel.DataBean();
model2.setId("3");
model2.setName("PREM3");
databeans.add(model2);
TelephoneDetailModel.DataBean model3 = new TelephoneDetailModel.DataBean();
model3.setId("4");
model3.setName("PREM4");
databeans.add(model3);
for (int i = 0; i < databeans.size(); i++) {
Log.e("ID", databeans.get(i).getId());
Log.e("NAME", databeans.get(i).getName());
}
输出
com.example.user33.demoapplication E/ID: 1
com.example.user33.demoapplication E/NAME: PREM
com.example.user33.demoapplication E/ID: 2
com.example.user33.demoapplication E/NAME: PREM2
com.example.user33.demoapplication E/ID: 3
com.example.user33.demoapplication E/NAME: PREM3
com.example.user33.demoapplication E/ID: 4
com.example.user33.demoapplication E/NAME: PREM4
- 试试这个
public class TelephoneDetailModel {
private List<DataBean> data;
public List<DataBean> getData() {
return data;
}
public void setData(List<DataBean> data) {
this.data = data;
}
public static class DataBean {
private String id;
private String name;
public DataBean() {
}
public DataBean(String id, String name) {
this.id = id;
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
现在要在
中添加数据arraylist
尝试此
List<TelephoneDetailModel.DataBean> databeans = new ArrayList();
databeans.add(new TelephoneDetailModel.DataBean("6","NEW NAME"));
答案 1 :(得分:2)
你好这样改变你的模型类(它使用起来非常简单)
- &GT; TelephoneModel
from rpy2.robjects import r
def decompose(series, frequency, s_window, **kwargs):
df = pd.DataFrame()
df['date'] = series.index
s = [x for x in series.values]
length = len(series)
s = r.ts(s, frequency=frequency)
decomposed = [x for x in r.stl(s, s_window, **kwargs).rx2('time.series')]
df['observed'] = series.values
df['trend'] = decomposed[length:2*length]
df['seasonal'] = decomposed[0:length]
df['residual'] = decomposed[2*length:3*length]
return df
}
- &GT; TelephoneDetailModel
if (m.find()) {
String matched = m.group(0);
int addToArray = Integer.parseInt(matched);
playerRanking[i] = addToArray;
System.out.println(i);
}
}
- &GT;你的活动
public class TelephoneModel {
private String id;
private String name;
public TelephoneModel(String id,String name) {
this.id=id;
this.name=name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
如果有任何问题可以随意问我......
答案 2 :(得分:1)
TelephoneModel类和TelephoneDetailModel中的DataBean不同,您无法将Datadean添加到另一个列表