![](/img/trans.png)
[英]Kotlin - EditText in Inflated View keyboard show on back with black opacity
[英]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 編輯文本,從所有四個視圖和顯示它們,有什么想法嗎? 我能在這里做什么?
我想從 4 個 EditTexts 中的每一個中獲取數據
在每個 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的position
如果你需要所有的edittext值然后使用for循環這樣
for(int i=0;i<list.length;i++){
Log.d("value","list.get(i).getText.toString");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.