1

我想创建多个相同类型的视图。我已经创建了这里是代码。

    LinearLayout mainRoot = (LinearLayout) findViewById(R.id.wrapper);          
    LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v=inflater.inflate(R.layout.customlayout, null);
    mainRoot.addView(v);

自定义布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"   
    android:background="#ffffff"
    android:id="@+id/subroot"
 >
<EditText
                 android:id="@+id/name"
                 android:layout_width="wrap_content"
                 android:layout_height="50dip"
                 android:layout_alignParentLeft="true"
                 android:layout_alignParentRight="true"
                 android:layout_below="@+id/undeline"
                 android:layout_marginTop="10dip"
                 android:ems="10"
                 android:inputType="textPersonName"
                 android:padding="5dip"
 />
<Button
      android:id="@+id/allegybutton1"
      style="?android:attr/buttonStyleSmall"
      android:layout_width="35dip"
      android:layout_height="35dip"
      android:layout_alignParentRight="true"
      android:layout_alignParentTop="true"
    />
</RelativeLayout>

现在假设我创建了 10 个相同类型的视图。如何区分每个资源 ID。

例如

EditText username = (EditText)v.findViewById(R.id.name);

对于 10 个视图,资源 ID 是相同的!有没有可能区分ID。

如何设置每个 EditText 的值。

有人可以帮我吗!

任何帮助都会很棒。!!谢谢。

4

0 回答 0