Android:向容器视图动态添加视图

Android:向容器视图动态添加视图,android,android-arrayadapter,android-spinner,Android,Android Arrayadapter,Android Spinner,嗨,我是动态创建行项目的,每当我点击按钮时,我都会膨胀编辑文本行并将其添加到我的容器中。我在行中有一个微调器,对于特定的微调器,我正在设置一个数组适配器 问题是,当尝试使用微调器添加另一行时,我需要将同一组数组适配器也设置为第二行微调器,但这会产生问题,这会干扰第一个微调器,因为这两个微调器都来自同一个xml文件 如何为微调器提供多个ID,并将它们视为不同的微调器 addviewbtn.setOnClickListener(new View.OnClickListener() {

嗨,我是动态创建行项目的,每当我点击按钮时,我都会膨胀编辑文本行并将其添加到我的容器中。我在行中有一个微调器,对于特定的微调器,我正在设置一个数组适配器

问题是,当尝试使用微调器添加另一行时,我需要将同一组数组适配器也设置为第二行微调器,但这会产生问题,这会干扰第一个微调器,因为这两个微调器都来自同一个xml文件

如何为微调器提供多个ID,并将它们视为不同的微调器

 addviewbtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LayoutInflater layoutInflater =
                        (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                addView = layoutInflater.inflate(R.layout.quote_row, null);
                container.addView(addView);
                for (int i = 0; i < container.getChildCount(); i++) {
                    View view = container.getChildAt(i);


                    spinner = (Spinner) view.findViewById(R.id.product);

                    String[] items = new String[]{"1", "2", "three"};
                   ArrayAdapter<String> adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_spinner_dropdown_item, items);
                    spinner.setAdapter(adapter);

                }
            }
        });
addviewbtn.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
LayoutInflater LayoutInflater=
(LayoutFlater)getBaseContext().getSystemService(Context.LAYOUT\u充气机\u服务);
addView=layoutInflater.flate(R.layout.quote_行,空);
container.addView(addView);
对于(int i=0;i
quote_row.xml

<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="wrap_content">

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:weightSum="1">

            <TextView
                android:id="@+id/TextView04h" android:text="1"
                android:layout_weight="0.1"
                android:textColor="#000000"
                android:padding="10dp" android:gravity="center|center_vertical"
                android:layout_margin="2dp"
                android:layout_width="0dp"
                android:layout_height="wrap_content"/>

            <EditText
                android:id="@+id/quantity"
                android:layout_weight="0.1"
                android:textColor="#000000"
                android:padding="10dp" android:gravity="center"
                android:background="@drawable/edit_text_border"
                android:layout_margin="2dp"
                android:layout_width="0dp"
                android:layout_height="wrap_content"/>

            <Spinner
                android:id="@+id/product"
                android:layout_weight="0.4"
                android:textColor="#000000"
                android:padding="10dp" android:gravity="center"
                android:background="@drawable/edit_text_border"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_width="0dp"
                android:layout_height="44dp"/>
            <EditText
                android:id="@+id/unitprice"
                android:layout_weight="0.2"
                android:textColor="#000000"
                android:padding="10dp" android:gravity="center"
                android:background="@drawable/edit_text_border"
                android:layout_margin="2dp"
                android:layout_width="0dp"
                android:layout_height="wrap_content"/>
            <EditText
                android:id="@+id/exactprice"
                android:layout_weight="0.2"
                android:textColor="#000000"
                android:padding="10dp" android:gravity="center"
                android:background="@drawable/edit_text_border"
                android:layout_margin="2dp"
                android:layout_width="0dp"
                android:layout_height="wrap_content"/>
        </TableRow>



    </TableLayout>
</RelativeLayout>


place quote_row xml。@DheerubhaiBansal添加了xml文件
View view = container.getChildAt(i);
TableLayout table=(TableLayout)view.findViewbyId(R.id.table);
TableRow row=(TableRow)table.getChildAt(0);
spinner = (Spinner) row.getChildAt(2);