我有自定义对话框的 ListActivity , onClick 。自定义对话框包含微调器和EditText现在我无法获得EditText的值,而EditText的调试值将变为空白或“”。
protected void onListItemClick(ListView l, View v, int position, long id)
{
super.onListItemClick(l, v, position, id);
positionList=position;
HashMap<String,Object>temp =(HashMap<String ,Object>)list.get(position);
LayoutInflater inflater = (LayoutInflater) CommonScreen6.this.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.answer_screen,null);
AlertDialog.Builder alertDialog=new AlertDialog.Builder(CommonScreen6.this);
alertDialog.setTitle("Select Option");
alertDialog.setView(layout);
Spinner answerList=(Spinner)layout.findViewById(R.id.spinnerAnswerList);
ArrayAdapter<String> adapterAnswerType = new ArrayAdapter<String> (CommonScreen6.this, android.R.layout.simple_spinner_item,(ArrayList<String>)temp.get(Constants.answerDesc));
adapterAnswerType.setDropDownViewResource(android.R.layout.select_dialog_singlechoice);
answerList.setAdapter(adapterAnswerType);
answerList.setOnItemSelectedListener(this);
ArrayList<String> answerDescList=(ArrayList<String>)temp.get(Constants.answerDesc);
answerList.setSelection(answerDescList.indexOf(temp.get(Constants.defaultAnswerDesc)));
alertDialog.setPositiveButton("Submit",new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
LayoutInflater inflater = (LayoutInflater) CommonScreen6.this.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.answer_screen,null);
EditText editText=(EditText)layout.findViewById(R.id.remark);
String remark=editText.getText().toString();
HashMap<String,Object>temp =(HashMap<String ,Object>)list.get(positionList);
temp.put(Constants.remark, remark);
adapter.notifyDataSetChanged();
}
});
}
答案 0 :(得分:0)
您没有获得任何值的原因是您在读取值之前重新定义布局,从而将值重置为默认值。
我想你想在on v
参数上找到ViewById,而不是重新定义布局。
即代替
LayoutInflater inflater = (LayoutInflater) CommonScreen6.this.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.answer_screen,null);
EditText editText=(EditText)layout.findViewById(R.id.remark);
尝试类似
的内容EditText editText=(EditText)v.findViewById(R.id.remark);
您可能需要将v
变量设为final,以便使其正常工作。
我希望这会有所帮助。