0
我想基於我的JSON響應以編程方式繪製編輯文本。所有繪製完美,但我只能編輯最後一個和其他不可編輯,我可以'沒有得到他們的重點。任何想法可以解決這個問題?獲取在Android中以編程方式繪製的Edittext的焦點
RelativeLayout layout =(RelativeLayout)getActivity().findViewById(R.id.layout_items);
JSONArray result=(JSONArray)o;
for (int i = 0; i < result.length(); i++) {
try {
relativeLayoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
editText = new EditText(context);
editText.setHint(result.getJSONObject(i).getString(config.TAG_NAME));
editText.setPadding(0,20,0,0);
editText.setId(Integer.parseInt(result.getJSONObject(i).getString(config.TAG_ID)));
editText.setEnabled(true);
editText.setFocusableInTouchMode(true);
editText.requestFocus();
relativeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
relativeLayoutParams.addRule(RelativeLayout.CENTER_VERTICAL);
relativeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, layout.getId());
layout.addView(editText, relativeLayoutParams);
}
catch (Exception ex) {
}
}
}
三江源! @fsnasser上帝保佑你。^_ ^ –