没有从ActionBar上的EditText获取文本按钮单击

时间:2014-07-21 17:43:07

标签: android android-edittext android-view layout-inflater

我在我的应用中使用了ActionBar。我想从EditText中获取值,即在其他Layout上获取值。我试图获得该布局,然后获取EditText值。

获取EditText

的布局的代码
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);
}

它始终显示"没有添加文字"即使添加文本

,也会显示Toast消息

0 个答案:

没有答案