使用(是/否)片段创建编辑文本

问题描述 投票:0回答:1

我有一个contex菜单,在这里我可以选择在ListView上编辑或添加元素。我决定通过在片段中添加EditText来解决它。我有此代码:

  private void addItem(int position) {
        /*

        */
        monthAdapter.notifyDataSetInvalidated();
    }*  

如何通过询问用户是否要拒绝并从中获取字符串来创建EditText?

android android-fragments android-edittext
1个回答
0
投票
private void addItem(int position) {

        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setTitle("Введите Вашу новую вещь");

        // alert.setMessage("Message");

        final EditText input = new EditText(this);

        alert.setView(input);
        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                String qq = input.getText().toString();
                myArr.add(qq);
                monthAdapter.notifyDataSetInvalidated();

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

            }
        });
        alert.show();


    }
© www.soinside.com 2019 - 2024. All rights reserved.