更新时间:2023-01-23 21:11:23
这是你没有得到任何值的原因是因为你reinflating读取的值之前的布局,从而重置价值为默认值。
我想你想findViewById而不是reinflating布局上的 v
说法,是考虑到onListItemClick方法。
也就是说,而非
LayoutInflater吹气=(LayoutInflater)CommonScreen6.this.getSystemService(LAYOUT_INFLATER_SERVICE);
查看布局= inflater.inflate(R.layout.answer_screen,NULL);
EDITTEXT的EditText =(EditText上)layout.findViewById(R.id.remark);
尝试像
的EditText EDITTEXT =(EditText上)v.findViewById(R.id.remark);
您可能需要做出的 v
变量最后,为了这个工作。
我希望这有助于。
I have ListActivity , onClick of each item a Custom Dialog appears.Custom Dialog contains spinner and EditText Now i am not able to get the value of EditText, while debug value of EditText is coming as blank or "".
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();
}
});
}
The reason that you are not getting any values is because you are reinflating the layout just before you read the values, thus resetting values to the defaults.
I suppose that you would like to findViewById on the v
argument that was given to the onListItemClick method, instead of reinflating the layout.
That is, instead of
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);
try something like
EditText editText=(EditText)v.findViewById(R.id.remark);
You might need to make the v
variable final, in order for this to work.
I hope this helps.