用户可以创建超过 20-30 个 EditTextes,应用程序必须保存他们的。
我有一个问题:我不知道如何从这些 EditTextes 中获取文本。
这是我在 xml 文件中的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/editText_text" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/editext_amount" android:layout_weight="1"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/editText1_price" android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
这是我的活动代码:
layout_container = (LinearLayout)findViewById(R.id.layout_items);
View view_item = getLayoutInflater().inflate(R.layout.shop_item,layout_container,false);
layout_container.addView(view_item);
@Override
public void onClick(View view)
{
if(view == button_add_item)
{
field_count++;
if(field_count < 50)
{
View view_item = getLayoutInflater().inflate(R.layout.shop_item,layout_container,false);
layout_container.addView(view_item);
}
}
}
谢谢你=)