嗨,我一直在开发一个应用程序,其中我有一个加号按钮,而该加号按钮的onclick我正在放大布局。每次用户单击加号按钮时,都会创建一个新的布局,现在我将数据从editext添加到数据库中,到目前为止一切正常,但是我的问题是只有最后一个editext值存储在数据库中,我在布局中有两个editext我正在对API调用进行改造。 所以请有人在这里帮我
**编辑:调试代码并维护一个单独的arraylist,它返回正确的大小,但是,当我使用for循环发送数据时,如在第二段代码中看到的,只有最后一个数据被重复** < / p>
这里是膨胀布局的方法
public void makedifferentEditText() {
try {
View secondchild = getLayoutInflater().inflate(R.layout.update_extra_links_layout, null);
final LinearLayout update_extra_links_layout = (LinearLayout) secondchild.findViewById(R.id.update_extra_links_layout);
customtextTitle = (CustomEditTextThin) secondchild.findViewById(R.id.google_edit_link);
customeditTextLink = (CustomEditTextThin) secondchild.findViewById(R.id.facebook_edit_link);
google_tilte.add(customtextTitle);
google_link.add(customeditTextLink);
Log.e("title",google_tilte.toString());
Log.e("link",google_link.toString());
//String customLink = customeditTextLink.getText().toString();
AppCompatImageView removeimage = (AppCompatImageView) secondchild.findViewById(R.id.icon_remove_link);
//arrayLink.add(customLink);
//arrayLink.add(customtextTitle.getText().toString());
// for(int i=0;i<200;i++){
// customLink[i] = customeditTextLink.getText().toString();
// customGoogleLink[i] = customeditTextLink.getText().toString();
// }
eexId = (TextView) secondchild.findViewById(R.id.eeid);
rAlign.addView(update_extra_links_layout);
removeimage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
rAlign.removeView(update_extra_links_layout);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
这是我获取数据的方式
if(google_link!=null && google_link.size()>0) {
for(int j=0;j<google_link.size();j++) {
arrayTitle.add(google_link.get(j).getText().toString());
Log.e("array", arrayTitle.toString());
if (customtextTitle != null && customeditTextLink != null) {
if (arrayTitle != null) {
for (String link : arrayTitle) {
ExtraLinksObject links4 = new ExtraLinksObject();
String othergoogleTitle = customtextTitle.getText().toString();
String othergooglelink = link;//customeditTextLink.getText().toString();
String googleId = eexId.getText().toString();
links4.setLink(othergooglelink);
links4.setTitle(othergoogleTitle);
links4.setExID(googleId);
extraLinks.add(links4);
}
}
}
}
}
答案 0 :(得分:0)
您可以让一个孩子一个查看并添加到数据库中
for(int i = 0; i < rAlign.getChildCount();i++) {
View secondchild = rAlign.getChildAt(i);
customtextTitle = (CustomEditTextThin) secondchild.findViewById(R.id.google_edit_link);
customeditTextLink = (CustomEditTextThin) secondchild.findViewById(R.id.facebook_edit_link);
eexId = (TextView) secondchild.findViewById(R.id.eeid);
if (customtextTitle != null && customeditTextLink != null) {
ExtraLinksObject links4 = new ExtraLinksObject();
String othergoogleTitle = customtextTitle.getText().toString();
String othergooglelink = customeditTextLink.getText().toString();
String googleId = eexId.getText().toString();
links4.setLink(othergooglelink);
links4.setTitle(othergoogleTitle);
links4.setExID(googleId);
extraLinks.add(links4);
}
}
答案 1 :(得分:-1)
最后,我能够通过制作一个editext的数组列表并循环遍历来自行解决。 我希望这对以后的人有帮助
library(plyr)