1

I don't know how to handle this, I think I've search everywhere.. But this problem is just mysterious,. I got an activity named EditdataActivity

public class EditdataActivity extends ActionBarActivity{
    logclass clogs = new logclass();
    EditText edt_ln;
    EditText edt_lat;
    EditText edt_long;
    Button btn_cancel;
    Button btn_save;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dataedit);
        clogs =(logclass) getIntent().getSerializableExtra("MyClass");
        edt_ln = (EditText) findViewById(R.id.edt_Ln);
        edt_lat = (EditText) findViewById(R.id.edt_lat);
        edt_long = (EditText) findViewById(R.id.det_long);
        btn_cancel = (Button) findViewById(R.id.cancel_btn);
        btn_save = (Button) findViewById(R.id.btn_save);

        edt_ln.setText(clogs.getname());
        edt_lat.setText(clogs.getlatloc()+"");
        edt_long.setText(clogs.getlongloc()+"");

        OnClickListener savelistener = new OnClickListener() {          
            @Override
            public void onClick(View v) {
                //notifpopup("Save changes?");
             }
        };
        btn_save.setOnClickListener(savelistener);     

        OnClickListener cancellistener = new OnClickListener() {            
            @Override
            public void onClick(View v) {
                Intent intent1 = new Intent(EditdataActivity.this, AdddataclassActivity.class);
                intent1.putExtra("MyClass", clogs);  
                intent1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);   
                startActivity(intent1);
                overridePendingTransition (R.anim.open_main, R.anim.close_next);
             }
        };
        btn_cancel.setOnClickListener(cancellistener);

    }

    void notifpopup(String notif){
        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setTitle(notif);
        alert.setPositiveButton("YES", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                clogs.setname(edt_ln.getText().toString());
                double lat = Double.parseDouble(edt_lat.getText().toString());
                double longl = Double.parseDouble(edt_long.getText().toString());
                clogs.setlatloc(lat);
                clogs.setlongloc(longl);
            }
        });

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

                    }
           });

            alert.show();
    }   
}

and this is called from this activity

@Override
    protected void onCreate(Bundle savedInstanceState) {
        ........
        clogs =(logclass) getIntent().getSerializableExtra("MyClass");
        ........   

           Button edit_data = (Button) findViewById(R.id.btn_addattrbdel);
           OnClickListener editlistener = new OnClickListener() {           
                @Override
                public void onClick(View v) {
                    gotoeditview();
                 }
            };
            edit_data.setOnClickListener(editlistener); 
    }

    void gotoeditview(){
        Intent intentl = new Intent(this,EditdataActivity.class);
        intentl.putExtra("MyClass", clogs);  
        intentl.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
        startActivity(intentl);
        overridePendingTransition (R.anim.appear, R.anim.disappear);
    }

however an error occured when I execute it as shown in the logcat beloc

10-17 17:06:41.750: E/AndroidRuntime(707): FATAL EXCEPTION: main
10-17 17:06:41.750: E/AndroidRuntime(707): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ict.map_navigation/com.ict.map_navigation.EditdataActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
10-17 17:06:41.750: E/AndroidRuntime(707):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2070)
10-17 17:06:41.750: E/AndroidRuntime(707):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2095)
10-17 17:06:41.750: E/AndroidRuntime(707):  at android.app.ActivityThread.access$600(ActivityThread.java:134)
10-17 17:06:41.750: E/AndroidRuntime(707):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203)
10-17 17:06:41.750: E/AndroidRuntime(707):  at android.os.Handler.dispatchMessage(Handler.java:99)
10-17 17:06:41.750: E/AndroidRuntime(707):  at android.os.Looper.loop(Looper.java:137)
10-17 17:06:41.750: E/AndroidRuntime(707):  at android.app.ActivityThread.main(ActivityThread.java:4830)
10-17 17:06:41.750: E/AndroidRuntime(707):  at java.lang.reflect.Method.invokeNative(Native Method)
10-17 17:06:41.750: E/AndroidRuntime(707):  at java.lang.reflect.Method.invoke(Method.java:511)
10-17 17:06:41.750: E/AndroidRuntime(707):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
10-17 17:06:41.750: E/AndroidRuntime(707):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
10-17 17:06:41.750: E/AndroidRuntime(707):  at dalvik.system.NativeStart.main(Native Method)
10-17 17:06:41.750: E/AndroidRuntime(707): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
10-17 17:06:41.750: E/AndroidRuntime(707):  at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:110)
10-17 17:06:41.750: E/AndroidRuntime(707): ....

.. however as what I've read on some suggested solution I changed my EditdataActivity to Acitvity.. it did not have any errors.. but it only displays this ..

enter image description here

and my xml file for that activity is this..

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:gravity="center"
        android:text="Change Name of the Location" />

    <EditText
        android:id="@+id/edt_Ln"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/textView1"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/edt_Ln"
        android:gravity="center"
        android:text="Change Location" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView3"
        android:layout_marginTop="26dp"
        android:text="Longitude:"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView2"
        android:layout_marginTop="28dp"
        android:text="Latitude:"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <EditText
        android:id="@+id/edt_lat"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView3"
        android:layout_alignBottom="@+id/textView3"
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@+id/textView4"
        android:ems="10"
        android:inputType="number" />

    <EditText
        android:id="@+id/det_long"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView4"
        android:layout_alignBottom="@+id/textView4"
        android:layout_alignLeft="@+id/edt_lat"
        android:layout_alignParentRight="true"
        android:ems="10"
        android:inputType="number" />

    <Button
        android:id="@+id/btn_save"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/det_long"
        android:layout_marginTop="17dp"
        android:layout_toRightOf="@+id/btn_cancel"
        android:background="#00ced1"
        android:text="Save" />

    <Button
        android:id="@+id/btn_cancel"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/btn_save"
        android:layout_alignBottom="@+id/btn_save"
        android:layout_alignParentLeft="true"
        android:layout_alignRight="@+id/textView4"
        android:background="#ff0000"
        android:text="Cancel" />

</RelativeLayout>

I have other activity which is exactly like this in my project. but they all work fine, I tried.. Restarting my eclipse IDE.. but it did not work.. Please help, maybe I just forgot something. thanks.. and here is the Manifest file of my project..

Sorry for my long post...

Umair
  • 6,366
  • 15
  • 42
  • 50
ErenRavenHeart
  • 281
  • 3
  • 6
  • 15

2 Answers2

1

If you want to use ActionBarActivity, its theme must be a Theme.AppCompat theme (or descendant).

If you want to use Theme.Dialog theme, your activity should not extend ActionBarActivity.

Feng Dai
  • 633
  • 5
  • 9
1

If you want to create your own custom dialogs, create class who extends DialogFragment instead of creating activities. It's easy to use and you don't have to declare them in your manifest.

Use it like this:

public class EditDataDialog extends DialogFragment {

    // Properties here
    .....

    @Override
    public View onCreateView(LayoutInflater inflater,
            ViewGroup container, Bundle savedInstanceState)
    {
        View view = inflater.inflate(R.layout.activity_dataedit, container, false);

        // Properties init here
        .....

        return view;
    }
}

Then, in your main activity, call this:

// Show the "edit data" dialog
FragmentManager fm = getSupportFragmentManager();
EditDataDialog editDataDialog = new EditDataDialog();
editDataDialog.show(fm, "edit_data_dialog");
Allan Mermod
  • 806
  • 1
  • 8
  • 16