I am trtying to create this layout below, but I can seem to get the right layout that I need. What I'm trying to accomplish is have a customize dailog box, using a layout. I tried edit the xml below but if this is shown as a dialog the defined layout is a mess. Please help me understand what I need to do for this. THanks and looking forward. They dialog is SHOWING but the layout is not met.
This layout is what I am trying to accomplish:
Dialog:
View checkBoxView = View.inflate(this, R.layout.display_item_dialog, null);
CheckBox checkBox = (CheckBox)checkBoxView.findViewById(R.id.checkBox1);
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// Save to shared preferences
}
});
checkBox.setText("Search All Images");
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Image Preferences");
builder.setMessage(" Select from below ")
.setView(checkBoxView)
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
}).show();
display_item_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Map Category: BEVERAGES" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="200dip"
android:layout_height="200dip"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="14dp"
android:src="@drawable/sunny" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="TextView" />
<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="TextView" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/imageView1"
android:layout_marginRight="20dp"
android:layout_marginTop="47dp"
android:text="+" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView2"
android:layout_alignLeft="@+id/button1"
android:layout_marginBottom="14dp"
android:text="-" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button2"
android:layout_alignRight="@+id/button2"
android:layout_below="@+id/button1"
android:ems="10"
android:clickable="false" >
<requestFocus />
</EditText>
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView3"
android:layout_marginTop="33dp"
android:text="CheckBox" />
</RelativeLayout>
Try this:
You can refer to this tutorials
http://www.mkyong.com/android/android-custom-dialog-example/