我将视图充气 5 次,充气的视图有一个 EditText,现在屏幕上有 5 个 EditText,如何从这些 EditText 中获取文本

I inflated a view 5 times, the view which was inflated had a EditText, now i have 5 EditText on the screen, how to get the text from those EditTexts


public class MainActivity extends AppCompatActivity {



    EditText EditText1,EditText2,EditText3,EditText4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        EditText1 = findViewById(R.id.edittext);
        EditText2 = findViewById(R.id.edittext);
        EditText3 = findViewById(R.id.edittext);
        EditText4 = findViewById(R.id.edittext);


        addChildLayout();
        addChildLayout();
        addChildLayout();
        addChildLayout();
    }

    public void addChildLayout(){

        LayoutInflater layoutInfralte=(LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
       
        LinearLayout linearLayout=(LinearLayout)findViewById(R.id.infolayout);
      
        View view=layoutInfralte.inflate(R.layout.activity_main_layout, null);
        
        linearLayout.addView(view);

    }
}

我如何select EditText,从所有四个视图中查看并显示它们,有什么想法吗?我可以在这里做什么?

我想从 4 个 EditText 中获取数据

对每个 editText 引用使用 .getText()

public class MainActivity extends AppCompatActivity {



    EditText EditText1,EditText2,EditText3,EditText4;
List<EditText> list=new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        EditText1 = findViewById(R.id.edittext);
        EditText2 = findViewById(R.id.edittext);
        EditText3 = findViewById(R.id.edittext);
        EditText4 = findViewById(R.id.edittext);


        addChildLayout();
        addChildLayout();
        addChildLayout();
        addChildLayout();
    }

    public void addChildLayout(){

        LayoutInflater layoutInfralte=(LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
       
        LinearLayout linearLayout=(LinearLayout)findViewById(R.id.infolayout);
      
        View view=layoutInfralte.inflate(R.layout.activity_main_layout, null);
EditText inflatededitText=(EditText)view.findViewById(R.id.youredittextid);
list.add(inflatededitText);
        
        linearLayout.addView(view);

    }
}

现在您可以获得如下任何编辑文本

list.get(0).getText.toString

这里0是edittext的位置

如果你需要所有的 edittext 值然后像这样使用 for 循环

for(int i=0;i<list.length;i++){
 Log.d("value","list.get(i).getText.toString");
}