AlertDialog在ActivityGroup中不起作用

时间:2013-05-26 01:24:11

标签: android tabs alertdialog android-alertdialog activitygroup

我有一个主要活动有三个标签ADMINISTRADOR。 在第一个选项卡中,当我点击每个项目时必须离开一个AlertDialog时,我会调用list活动中的另一个活动与listview我有以下错误:

05-25 20:06:58.025: E/AndroidRuntime(26021): FATAL EXCEPTION: main
05-25 20:06:58.025: E/AndroidRuntime(26021): android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@44c227a8 is not valid; is your activity running?
05-25 20:06:58.025: E/AndroidRuntime(26021):    at android.view.ViewRoot.setView(ViewRoot.java:505)
05-25 20:06:58.025: E/AndroidRuntime(26021):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
05-25 20:06:58.025: E/AndroidRuntime(26021):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
05-25 20:06:58.025: E/AndroidRuntime(26021):    at android.view.Window$LocalWindowManager.addView(Window.java:424)
05-25 20:06:58.025: E/AndroidRuntime(26021):    at android.app.Dialog.show(Dialog.java:241)
05-25 20:06:58.025: E/AndroidRuntime(26021):    at utp.android.aplicacion.ListarAlumnos$1.run(ListarAlumnos.java:170)
05-25 20:06:58.025: E/AndroidRuntime(26021):    at android.app.Activity.runOnUiThread(Activity.java:3707)
05-25 20:06:58.025: E/AndroidRuntime(26021):    at utp.android.aplicacion.ListarAlumnos.onItemClick(ListarAlumnos.java:149)
05-25 20:06:58.025: E/AndroidRuntime(26021):    at android.widget.AdapterView.performItemClick(AdapterView.java:284)
05-25 20:06:58.025: E/AndroidRuntime(26021):    at android.widget.ListView.performItemClick(ListView.java:3382)
05-25 20:06:58.025: E/AndroidRuntime(26021):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:2394)
05-25 20:06:58.025: E/AndroidRuntime(26021):    at android.os.Handler.handleCallback(Handler.java:587)
05-25 20:06:58.025: E/AndroidRuntime(26021):    at android.os.Handler.dispatchMessage(Handler.java:92)
05-25 20:06:58.025: E/AndroidRuntime(26021):    at android.os.Looper.loop(Looper.java:123)
05-25 20:06:58.025: E/AndroidRuntime(26021):    at android.app.ActivityThread.main(ActivityThread.java:4627)
05-25 20:06:58.025: E/AndroidRuntime(26021):    at java.lang.reflect.Method.invokeNative(Native Method)
05-25 20:06:58.025: E/AndroidRuntime(26021):    at java.lang.reflect.Method.invoke(Method.java:521)
05-25 20:06:58.025: E/AndroidRuntime(26021):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
05-25 20:06:58.025: E/AndroidRuntime(26021):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-25 20:06:58.025: E/AndroidRuntime(26021):    at dalvik.system.NativeStart.main(Native Method)

主要活动:

public class Administrador  extends TabActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_administrador);

        TabHost tabHost = getTabHost();

        TabSpec photospec = tabHost.newTabSpec("Mantenimiento");
        photospec.setIndicator("Mantenimiento", getResources().getDrawable(R.drawable.icon_photos_tab));
        Intent photosIntent = new Intent(this, ListarAlumnos.class);
        photospec.setContent(photosIntent);

        TabSpec songspec = tabHost.newTabSpec("Asignaciones");
        songspec.setIndicator("Asignaciones", getResources().getDrawable(R.drawable.icon_songs_tab));
        Intent songsIntent = new Intent(this, Asignaciones.class);
        songspec.setContent(songsIntent);

        TabSpec videospec = tabHost.newTabSpec("Reportes");
        videospec.setIndicator("Reportes", getResources().getDrawable(R.drawable.icon_videos_tab));
        Intent videosIntent = new Intent(this, Reportes.class);
        videospec.setContent(videosIntent);

        // Adding all TabSpec to TabHost
        tabHost.addTab(photospec); // Adding photos tab
        tabHost.addTab(songspec); // Adding songs tab
        tabHost.addTab(videospec); // Adding videos tab



    }

}

活动ListarAlumnos:

public class ListarAlumnos extends ActivityGroup implements OnItemClickListener{


    public static MenuAdministrador context; 

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        View viewToLoad = LayoutInflater.from(this.getParent()).inflate(R.layout.activity_listar_alumnos, null);
        this.setContentView(viewToLoad);

        //setContentView(R.layout.activity_listar_alumnos);




        lstalumnos = (ListView)findViewById(R.id.LISTAPRUEBA);
        lstalumnos.setOnItemClickListener(this);

        ///THE LISTVIEW CONTAINS DATA OF DATABASE 

    }



    public void onItemClick(AdapterView<?> arg0, View arg1, final int arg2, long arg3) {

        Toast.makeText(getApplicationContext(), "ok", 1000).show();
            //Context appContext = this.getApplicationContext();
            //Dialog builder = new Dialog(appContext);

        runOnUiThread(new Runnable() {

            public void run() {
                // TODO Auto-generated method stub

                final AlertDialog.Builder builder = new AlertDialog.Builder(getParent());
                ///builder.setTitle("Matenimiento de "+ Apellido.get(arg2));
                ///builder.setMessage("Por favor, escoger accion : ");
                ///builder.setPositiveButton("Actualizar", new DialogInterface.OnClickListener()
                ///{

                ///public void onClick(DialogInterface dialog, int which) {
                ///Actualizar(arg2);
                ///}
                ///});
                ///builder.setNegativeButton("Deshabilitar", new DialogInterface.OnClickListener() {

                ///public void onClick(DialogInterface dialog, int which) {
                ///     Eliminar(arg2);
                ///}
                ///});
                builder.create().show();            


            }})
        ;

    }

1 个答案:

答案 0 :(得分:0)

处理类似问题的问题很多。上下文似乎存在问题。参见:

how to show alert inside an activity group?

Dialog Box in Activity group inside a TabActivity not working

Problems on an activitygroup under tabshost

希望这有帮助。