我的xml文件中有大约200个editText。
我想在我的java文件中立即获取所有输入值。
如果没有找到所有200个ID,我有什么方法可以做到这一点。
答案 0 :(得分:0)
试试这个:
private LinearLayout ll;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
ll=(LinearLayout)findViewById(R.id.ll_view);
final int childcount = ll.getChildCount();
for (int i = 0; i < childcount; i++) {
View v = ll.getChildAt(i);
if (v instanceof EditText) {
Log.d("EditText Value", ((EditText) v).getText().toString());
}
}
}
答案 1 :(得分:0)
在linearlayout中创建200 EditText
LinearLayout mRlayout = (LinearLayout) findViewById(R.id.llMainLayout);
LinearLayout.LayoutParams mRparams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)
for (int i = 0; i < 200; i++) {
EditText myEditText = new EditText(context);
myEditText.setLayoutParams(mRparams);
mRlayout.addView(myEditText);
}
在arraylist
中检索值ArrayList<String> alEditTextInputs = new ArrayList<>();
for(int j=0;j<mRlayout.getChildCount();j++){
alEditTextInputs.add(((EditText)mRlayout.getChildAt(j)).getText().toString());
}
答案 2 :(得分:0)
您需要在父视图中以递归方式调用,以在视图中查找ViewGroup viewGroup = //Your parent layout it render your child view.
int count = viewGroup .getChildCount();
for(int i =0;i<count;i++)
{
View v = viewGroup .getChildAt(i);
if(v instanceof Edittext)
{
// you got the edittext
EditText s = (EditText) v;
Log.i("Item selected",s.getText().toString());
}
}
的实例。
<input id="status_action" name="status_action" value="1" type="text" readonly="readonly">
<a href="javascript:void(0)" id="status_alert" class="btn btn-success btn-xs"><i class="fa fa-envelope-o" aria-hidden="true"></i> unread </a>
<script>
$(document).ready(function(){
if ($('#status_action').val() == 0 ) {
$('#status_alert').find('i').addClass('fa fa-envelope-open-o').removeClass('fa fa-envelope-o');
}
})
</script>
答案 3 :(得分:0)
请点击此链接