0

In my app, I have a dual tabbed activity, each tab corresponding to a fragment. In one of my tabs, I prompt the user for an option, which upon confirmation, should switch the tab. So my code for creating the dialog, and switching the tab looks like the following:

new AlertDialog.Builder(getActivity())
    .setMessage("Login now with email?")
    .setTitle("Prompt")
    .setPositiveButton("Yes", 
                       new DialogInterface.OnClickListener(){ 
                                 public void onClick(DialogInterface dialog, int which){
                                           getActivity().getActionBar().setSelectedNagivationItem(0)})
    .show();

However, when I run it, I get a

java.lang.RuntimeException: Unable to instantiate activity 
ComponentInfo com.package.app/com.package.app.activityname}: 
java.lang.ClassCastException: com.package.app.activityname cannot be cast to 
android.app.Activity

This error only occurs when I call the method from within the dialog, if I run it when the dialog is not on front, it works. I have also attempted to do it in OnResume() after the dialog dismisses, but it gives me the same error.

sparkonhdfs
  • 1,313
  • 2
  • 17
  • 31

1 Answers1

0

just for info, have you tried it with another method for changing tabs inside the alertdialog ? :) for example:

        TabHost tabHost =  (TabHost) findViewById(android.R.id.YOURTABHOST);
      tabHost.setCurrentTab(0); 
Matej Špilár
  • 2,617
  • 3
  • 15
  • 28