嘿,我想进行对话。但是没有显示整个对话框,仅显示了底部的3个图像按钮:这里出了什么问题?当我单击对话框中的按钮时,即使我做了一个开关盒也没有任何反应。
customtype_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AutoMode"
android:background="@color/black" >
<RelativeLayout
android:id="@+id/dialog_relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:layout_above="@+id/dialog_relativeLayout2"
android:layout_centerHorizontal="true" >
<Button
android:id="@+id/dialog_btn1"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="3dp"
android:background="@drawable/track_run"
android:layout_alignRight="@+id/dialog_relativeLayout1"
android:layout_alignTop="@+id/dialog_relativeLayout1"
/>
<Button
android:id="@+id/dialog_btn2"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="3dp"
android:background="@drawable/track_bike"
android:layout_alignTop="@+id/dialog_relativeLayout1"
android:layout_toRightOf="@+id/dialog_btn1"
/>
<Button
android:id="@+id/dialog_btn3"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="3dp"
android:layout_toRightOf="@+id/dialog_btn2"
android:background="@drawable/track_walk"
/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/dialog_relativeLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
>
<Button
android:id="@+id/dialog_btn4"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="3dp"
android:background="@drawable/track_ski"
android:layout_alignRight="@+id/dialog_relativeLayout2"
android:layout_alignTop="@+id/dialog_relativeLayout2"
/>
<Button
android:id="@+id/dialog_btn5"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="3dp"
android:background="@drawable/track_boat"
android:layout_alignTop="@+id/dialog_relativeLayout2"
android:layout_toRightOf="@+id/dialog_btn4"
/>
<Button
android:id="@+id/dialog_btn6"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="3dp"
android:background="@drawable/track_snow_boarding"
android:layout_alignTop="@+id/dialog_relativeLayout2"
android:layout_toRightOf="@+id/dialog_btn5"
/>
</RelativeLayout>
</RelativeLayout>
routeType = (ImageButton)findViewById(R.id.saveRoute_activityType);
routeType.setOnClickListener(typeListener);
SaveRouteActivity.java
这是我的听众。
View.OnClickListener typeListener = new OnClickListener() {
public void onClick(View v) {
switch(v.getId()){
case R.id.saveRoute_activityType:
Dialog typedialog = new Dialog(SaveRouteActivity.this);
typedialog.setContentView(R.layout.customtype_dialog);
typedialog.setTitle("Select type");
typedialog.setCancelable(true);
typedialog.show();
break;
case R.id.dialog_btn1:
txtType.setText("Run");
routeType.setBackgroundResource(R.drawable.track_run);
break;
case R.id.dialog_btn2:
txtType.setText("Bike");
routeType.setBackgroundResource(R.drawable.track_bike);
break;
case R.id.dialog_btn3:
txtType.setText("Walk");
routeType.setBackgroundResource(R.drawable.track_walk);
break;
case R.id.dialog_btn4:
txtType.setText("Ski");
routeType.setBackgroundResource(R.drawable.track_ski);
break;
case R.id.dialog_btn5:
txtType.setText("Boat");
routeType.setBackgroundResource(R.drawable.track_boat);
break;
case R.id.dialog_btn6:
txtType.setText("Snowboarding");
routeType.setBackgroundResource(R.drawable.track_snow_boarding);
break;
}
}
};
最佳答案
我的猜测是typedialog.setContentView(R.layout.customtype_dialog);
被忽略了,因为对话框还没有被夸大。若要解决此问题,您应该创建Dialog
的子类并在其setContentView()
方法中调用onCreate()
。