我的应用程序。有一个按钮,如果它按下 2 个 editText 字段 aper ,如果再次按下它,则 2 个其他 editText 字段 aear 等等。我想将此字段中的所有数据保存在arrayList(或任何结构)中这是我的代码示例1-出现的EditText字段:
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="50dp"
这是 mainAcvtivity 代码:
LinearLayout lLayout;
ArrayList<String> mArray = new ArrayList<String>();
int numberOfBoxes = 2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
lLayout = (LinearLayout)findViewById(R.id.layout1);
final EditText AddEduDate = (EditText)inflater.inflate(R.layout.text, null);
final EditText AddEduInfo = (EditText)inflater.inflate(R.layout.text, null);
Button b2 = (Button)findViewById(R.id.button2);
Button b = (Button)findViewById(R.id.button1);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (lLayout.getChildAt(numberOfBoxes) == null) {
lLayout.addView(AddEduDate);
lLayout.addView(AddEduInfo);
numberOfBoxes += 2;
}
}
});