gpt4 book ai didi

android - 无法使用 Theme.Dialog 启动 Activity

转载 作者:行者123 更新时间:2023-11-29 20:59:59 25 4
gpt4 key购买 nike

我不知道如何处理这个问题,我想我到处都在搜索..但是这个问题很神秘,。我有一个名为 EditdataActivity 的 Activity

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();
}
}

这是从这个 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);
}

然而,当我执行它时出现错误,如 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): ....

.. 然而,正如我在一些建议的解决方案中所读到的那样,我将我的 EditdataActivity 更改为 Acitvity.. 它没有任何错误.. 但它只显示这个..

enter image description here

我的那个 Activity 的 xml 文件是这个..

<?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>

我的项目中还有其他与此完全相同的 Activity 。但它们都工作正常,我试过了.. 重新启动我的 eclipse IDE.. 但它没有用.. 请帮忙,也许我只是忘记了什么。谢谢..这是我项目的 list 文件..

对不起,我的帖子太长了......

最佳答案

如果您想创建自己的自定义对话框,请创建扩展 DialogFragment 的类,而不是创建 Activity 。它易于使用,您不必在 list 中声明它们。

像这样使用它:

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;
}
}

然后,在您的主要 Activity 中,调用它:

// Show the "edit data" dialog
FragmentManager fm = getSupportFragmentManager();
EditDataDialog editDataDialog = new EditDataDialog();
editDataDialog.show(fm, "edit_data_dialog");

关于android - 无法使用 Theme.Dialog 启动 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26421782/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com