小编She*_*Sap的帖子

从 alertDialog 构建器获取 editText 值

我是新来的android。我需要获得editText's价值来搜索某些东西。但是当我运行程序时,错误出现在null pointer exception.

“EditText etSearch”没有得到它的文本。

请帮我。谢谢。

public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_search) {
            AlertDialog.Builder builder = new AlertDialog.Builder(
                    MainActivity.this);
            // Get the layout inflater
            LayoutInflater inflater = MainActivity.this.getLayoutInflater();

            // Inflate and set the layout for the dialog …
Run Code Online (Sandbox Code Playgroud)

android android-dialog

5
推荐指数
1
解决办法
8036
查看次数

标签 统计

android ×1

android-dialog ×1