Demo:
1)Custom Activity:
4)Download this Project Click Here
1)Custom Activity:
package
com.venkool.customdialogdemo;
import
android.app.Activity;
import
android.app.Dialog;
import
android.os.Bundle;
import
android.view.View;
import
android.view.View.OnClickListener;
import android.widget.Button;
import
android.widget.EditText;
import
android.widget.Toast;
public class
CustomDialogDemoActivity extends Activity {
/** Called when the activity is first
created. */
Button btnCustomDialog;
EditText edtUserName, edtPassword;
Dialog customDialog;
String Username, Password;
@Override
public void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnCustomDialog = (Button)
findViewById(R.id.showDialog);
btnCustomDialog.setOnClickListener(new
OnClickListener() {
@Override
public void onClick(View v)
{
// TODO
Auto-generated method stub
customDialog = new
Dialog(CustomDialogDemoActivity.this);
customDialog.setTitle("Custom
Dialog");
customDialog.setContentView(R.layout.custom_dialog);
customDialog.show();
Button btnSave =
(Button) customDialog
.findViewById(R.id.button1);
Button btnCancel =
(Button) customDialog
.findViewById(R.id.button2);
edtUserName = (EditText) customDialog
.findViewById(R.id.editText1);
edtPassword = (EditText) customDialog
.findViewById(R.id.editText2);
btnSave.setOnClickListener(new
OnClickListener() {
@Override
public void onClick(View v)
{
// TODO
Auto-generated method stub
Username = edtUserName.getText().toString();
Password = edtPassword.getText().toString();
Toast.makeText(getApplicationContext(),
Username + "-" + Password, 3000).show();
}
});
btnCancel.setOnClickListener(new
OnClickListener() {
@Override
public void onClick(View v)
{
// TODO
Auto-generated method stub
Toast.makeText(getApplicationContext(),
"Cancel", 3000)
.show();
}
});
}
});
}
}
2)main.xml:
<?xml version="1.0"
encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:orientation="vertical"
>
<Button
android:id="@+id/showDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="84dp"
android:text="Custom
Dialog" />
</RelativeLayout>
3)custom.xml:
<?xml version="1.0"
encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:orientation="vertical"
>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter your
Name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
/>
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter
Password"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
/>
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save"
/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
/>
</TableRow>
</LinearLayout>