Android 无法从ActionBar按钮上的EditText获取文本单击
我在我的应用程序中使用了ActionBar。我想从EditText(即其他版面)中获取值。我已经尝试获取该布局,然后获取EditText值 获取编辑文本所在布局的代码Android 无法从ActionBar按钮上的EditText获取文本单击,android,android-edittext,android-view,layout-inflater,Android,Android Edittext,Android View,Layout Inflater,我在我的应用程序中使用了ActionBar。我想从EditText(即其他版面)中获取值。我已经尝试获取该布局,然后获取EditText值 获取编辑文本所在布局的代码 public View textInputChecks() { LayoutInflater mLayoutInflater = getLayoutInflater(); View textQrView = mLayoutInflater.inflate(R.layout.text_qr, null);
public View textInputChecks() {
LayoutInflater mLayoutInflater = getLayoutInflater();
View textQrView = mLayoutInflater.inflate(R.layout.text_qr, null);
return textQrView;
}
点击ActionBar按钮的代码
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO This is really needed to make app icon a toggle of nav drawer.
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
} else {
switch (item.getItemId()) {
case R.id.action_ok:
View textInputView = textInputChecks();
EditText textInput = (EditText) textInputView.findViewById(R.id.qrTextInput);
String text = textInput.getText().toString();
if (text.length()>0) {
Toast.makeText(getApplicationContext(), "Ok",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "No Text added",
Toast.LENGTH_LONG).show();
}
break;
default:
break;
}
}
return super.onOptionsItemSelected(item);
}
即使将文本添加到
ViewGroupChangeView
,它也始终显示“No Text Added”Toast消息,因为textInputChecks
函数在ViewGroup textQrView=mLayoutInflater.flate(R.layout.Text\u qr,null)中显示空值错误;您是否也播放了视图组
?并尝试LayoutInflater充气器=(LayoutInflater)context.getSystemService(context.LAYOUT\u充气器\u服务)代码>取而代之的是,您的充气机仍保持不变。无错误且未获取文本您是否也更改了View textInputView=textInputChecks()代码>到视图组?