0

enter code hereListViewのonItemClickイベントでAlertDialogを作成していますが、エラーが発生します

Failed to handle callback; interface not implemented, 
callback:android.widget.AbsListView$1@41b28670 

そして私のコードはここにあります:

public void onItemClick(AdapterView<?> parent, View view, int position,long id) {
    alertDialog = new AlertDialog.Builder(RemoteDeviceActivity.this).create(); //alertDialog is global AlertDialog variable
    alertDialog.setTitle("Version Mismatch");
    alertDialog.setMessage("My Message");
    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {                 
            alertDialog.dismiss();
        } 
    });
    alertDialog.show();
}

これは私のlogcatです:

    07-05 14:48:44.402: E/Handler(6217): Failed to handle callback; interface not          implemented, callback:android.widget.AbsListView$1@41b79c38
    07-05 14:48:44.402: E/Handler(6217):
 android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@41a668d0 is not valid; 
is your activity running?
    07-05 14:48:44.402: E/Handler(6217):    at android.view.ViewRootImpl.setView(ViewRootImpl.java:570)
    07-05 14:48:44.402: E/Handler(6217):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:406)
    07-05 14:48:44.402: E/Handler(6217):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:320)
    07-05 14:48:44.402: E/Handler(6217):    at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:152)
    07-05 14:48:44.402: E/Handler(6217):    at android.view.Window$LocalWindowManager.addView(Window.java:557)
    07-05 14:48:44.402: E/Handler(6217):    at android.app.Dialog.show(Dialog.java:301)
    07-05 14:48:44.402: E/Handler(6217):    at android.app.AlertDialog$Builder.show(AlertDialog.java:932)
    07-05 14:48:44.402: E/Handler(6217):    at com.np.obelix.RemoteDeviceActivity.onItemClick(RemoteDeviceActivity.java:208)
    07-05 14:48:44.402: E/Handler(6217):    at android.widget.AdapterView.performItemClick(AdapterView.java:292)
    07-05 14:48:44.402: E/Handler(6217):    at android.widget.AbsListView.performItemClick(AbsListView.java:1099)
    07-05 14:48:44.402: E/Handler(6217):    at android.widget.ListView.performItemClick(ListView.java:4758)
    07-05 14:48:44.402: E/Handler(6217):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:2556)
    07-05 14:48:44.402: E/Handler(6217):    at android.widget.AbsListView$1.run(AbsListView.java:3223)
    07-05 14:48:44.402: E/Handler(6217):    at android.os.Handler.handleCallback(Handler.java:607)
    07-05 14:48:44.402: E/Handler(6217):    at android.os.Handler.dispatchMessage(Handler.java:92)
    07-05 14:48:44.402: E/Handler(6217):    at android.os.Looper.loop(Looper.java:154)
    07-05 14:48:44.402: E/Handler(6217):    at android.app.ActivityThread.main(ActivityThread.java:4974)
    07-05 14:48:44.402: E/Handler(6217):    at java.lang.reflect.Method.invokeNative(Native Method)
    07-05 14:48:44.402: E/Handler(6217):    at java.lang.reflect.Method.invoke(Method.java:511)
    07-05 14:48:44.402: E/Handler(6217):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    07-05 14:48:44.402: E/Handler(6217):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    07-05 14:48:44.402: E/Handler(6217):    at dalvik.system.NativeStart.main(Native Method)
4

2 に答える 2

1

Azmat私はあなたがcreateを使用する必要はないと思います

alertDialog = new AlertDialog.Builder(RemoteDeviceActivity.this).create();
i used this code and is working for me try this 

    AlertDialog.Builder builder = new AlertDialog.Builder(Normal_Score.this);


            builder.setMessage(" Are you sure you want to quit? " + 
                    "  You will loose data if you quit without saving "
                        +" Do You want to save data before you quit ?");
             builder.setCancelable(false)
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                             public void onClick(DialogInterface dialog, int id) {


                                 submit();
                                 Intent i = new Intent(Normal_Score.this, 
                                         Playaroud.class);
                                i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                // i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                finish();
                                startActivity(i);
                                       }
                                   })
            .setNegativeButton("No", new DialogInterface.OnClickListener() {
                             public void onClick(DialogInterface dialog, int id) {
                                            dialog.cancel();

                                            Intent i = new Intent(Normal_Score.this, 
                                                     Playaroud.class);
                                            i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

                                            finish(); 
                                            startActivity(i); 
                             }
                                   }).show();
于 2012-07-05T08:58:19.713 に答える
0

このコードを試してください、

 listView.setOnItemClickListener(new OnItemClickListener() {

                public void onItemClick(AdapterView<?> listView, View view,
                        int pos, long id) {
                    // TextView textView = (TextView) view.findViewById(
                    // android.R.id.text1 );
                    // toast( (String) textView.getText() );
                    callAlertDialog();
                }
            });

protected void callAlertDialog() {
        // TODO Auto-generated method stub
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                ListViewActivity.this);

        // set title
        alertDialogBuilder.setTitle("Your Title");

        // set dialog message
        alertDialogBuilder
                .setMessage("Click yes to exit!")
                .setCancelable(false)
                .setPositiveButton("Yes",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                // if this button is clicked, close
                                // current activity
                                ListViewActivity.this.finish();
                            }
                        })
                .setNegativeButton("No", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // if this button is clicked, just close
                        // the dialog box and do nothing
                        dialog.cancel();
                    }
                });

        // create alert dialog
        AlertDialog alertDialog = alertDialogBuilder.create();

        // show it
        alertDialog.show();
    }
于 2012-07-05T08:59:10.013 に答える