android对话框无法为setPositiveButton()提供资金支持

时间:2015-01-18 06:20:00

标签: android android-fragments android-adapter

我在适配器中有一个特定项目的监听器。当我点击它时,我想显示一个对话框。我的问题是我无法得到我的对话框" builder.setPositiveButton(" Cancel",new deleteRow());"上班。我永远无法找到我的任何功能。如何让对话框运行功能?

在我的片段中

public void getSavedVideos() {
        mydb = new MySQLiteHelper(getActivity());
        listView.setEmptyView(rootview.findViewById(R.id.noSavedVideosTextView));

        //Get IDs of all rows in the db
        ArrayList savedVideoIDs = mydb.getAllSavedVideo();

        mSavedVideoAdapter = new SavedVideoAdapter(getActivity(), savedVideoIDs, mydb);
        listView.setAdapter(mSavedVideoAdapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                View cancel = view.findViewById(R.id.x);
                cancel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        getActivity().showDialog(DIALOG_ALERT);
                    }
                });

                Intent myIntent = new Intent(getActivity(), UploadVideoActivity.class);
                startActivity(myIntent);
            }
            @Override
            protected Dialog onCreateDialog(int id) {
                switch (id) {
                    case DIALOG_ALERT:
                        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity().getApplicationContext());
                        builder.setTitle("Remove Video");
                        builder.setMessage("hkjh.");
                        builder.setCancelable(true);
                        builder.setPositiveButton("Cancel", new CancelOnClickListener());
                        builder.setNegativeButton("Remove", new deleteRow());
                        AlertDialog dialog = builder.create();
                        dialog.show();
                }
                return onCreateDialog(id);
            }

        });


    }
    public void deleteRow() {

    }

1 个答案:

答案 0 :(得分:0)

改变这个:

builder.setNegativeButton("Remove", new deleteRow()); 

到此:

 ad.setPositiveButton("Buy",new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    //do everi ting you want
                }
            });

工作

此处示例对话框包含操作:

AlertDialog.Builder ad = new AlertDialog.Builder(MainActivity.this);
            ad.setTitle("PRO_VISION");
            ad.setMessage("for use Settings you must buy pro_vision only pro user can use this");
            ad.setPositiveButton("Buy",new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    Intent is = new Intent(MainActivity.this,MainActivity4.class);
                    startActivityForResult(is,12);
                }
            });
            ad.setNegativeButton("cancel",null);
            ad.show();

在某些视图setOnClickListener中的onCreate上使用它 它必须是工作