如何将用户在编辑文本框中输入的文本添加到列表视图中?

3
我已经创建了一个包含ListView的布局。我在其中添加了一个按钮,当点击它时,会弹出一个带有编辑文本框和两个选项“确定”和“取消”的警告对话框。 我想将用户在编辑文本框中输入的内容添加到ListView中。请问有谁可以帮我解决如何添加的问题?
以下是代码,它展示了警告对话框,value必须显示为ListView的项目。
 if(v.getId() == addbtn.getId())
    {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);

    alert.setTitle("Add new location");


    // Set an EditText view to get user input 
    final EditText input = new EditText(this);
    alert.setView(input);

    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int whichButton) {
    Editable value = input.getText();
    // Do something with value!
    }
    });

    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int whichButton) {
    // Canceled.
    }
    });

    alert.show();



    }
1个回答

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接