How to create a form in dialog box,Here i use sample feed back form inside of the custom dialogbox,First u have to create a button in main.xml file,Because when the button is press ,FeedBack Form can open in customdialogbox,so thats why i had put a Button(Press Dialog).After that you also create a new xml file name as dialog.xml,In that xml ,i use Name,Mail,Comment and two buttons like send and cancel.
static final int CUSTOM_DIALOG_ID = 0;
Button customDialog_Dismiss;
The class have to declare as a
its a very few line code to creat a dialogbox.Just button press click listener,Dialog onCreateDialog and cancel button listener.
here i put full code .just check it
public class FeedbackFormusingInsideDialogBox extends Activity {
static final int CUSTOM_DIALOG_ID = 0;
Button customDialog_Dismiss;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button buttonStartDialog = (Button)findViewById(R.id.startdialog);
buttonStartDialog.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
showDialog(CUSTOM_DIALOG_ID);
}
});
}
private Button.OnClickListener customDialog_DismissOnClickListener = new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
dismissDialog(CUSTOM_DIALOG_ID);
}
};
@Override
protected Dialog onCreateDialog(int id) {
// TODO Auto-generated method stub
Dialog dialog = null;;
switch(id) {
case CUSTOM_DIALOG_ID:
dialog = new Dialog(this);
dialog.setContentView(R.layout.dialogbox);
dialog.setTitle("Feed Back Form");
customDialog_Dismiss = (Button)dialog.findViewById(R.id.button2);
customDialog_Dismiss.setOnClickListener(customDialog_DismissOnClickListener);
break;
}
return dialog;
}
}
code for dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical" android:layout_height="wrap_content">
<LinearLayout android:id="@+id/linearLayout1" android:layout_height="wrap_content" android:layout_width="match_parent">
<TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Name" android:textSize="15dp" android:layout_marginLeft="10dp" android:layout_marginTop="5dp"></TextView>
<EditText android:id="@+id/editText1" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:layout_width="200dp" android:layout_marginLeft="16dp"></EditText>
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/linearLayout2">
<TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Mail Id:" android:layout_marginTop="5dp" android:layout_marginLeft="5dp"></TextView>
<EditText android:id="@+id/editText2" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:layout_width="200dp" android:layout_marginLeft="16dp"></EditText>
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/linearLayout3">
<TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Comment" android:layout_marginLeft="5dp" android:layout_marginTop="5dp"></TextView>
<EditText android:id="@+id/editText3" android:layout_height="100dp" android:layout_width="200dp"></EditText>
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/linearLayout4">
<Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Send" android:layout_marginLeft="70dp"></Button>
<Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Cancel"></Button>
</LinearLayout>
</LinearLayout>
Then i have to create a main class name as FeedbackFormusingInsideDialogBox.java<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical" android:layout_height="wrap_content">
<LinearLayout android:id="@+id/linearLayout1" android:layout_height="wrap_content" android:layout_width="match_parent">
<TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Name" android:textSize="15dp" android:layout_marginLeft="10dp" android:layout_marginTop="5dp"></TextView>
<EditText android:id="@+id/editText1" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:layout_width="200dp" android:layout_marginLeft="16dp"></EditText>
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/linearLayout2">
<TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Mail Id:" android:layout_marginTop="5dp" android:layout_marginLeft="5dp"></TextView>
<EditText android:id="@+id/editText2" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:layout_width="200dp" android:layout_marginLeft="16dp"></EditText>
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/linearLayout3">
<TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Comment" android:layout_marginLeft="5dp" android:layout_marginTop="5dp"></TextView>
<EditText android:id="@+id/editText3" android:layout_height="100dp" android:layout_width="200dp"></EditText>
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/linearLayout4">
<Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Send" android:layout_marginLeft="70dp"></Button>
<Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Cancel"></Button>
</LinearLayout>
</LinearLayout>
static final int CUSTOM_DIALOG_ID = 0;
Button customDialog_Dismiss;
The class have to declare as a
its a very few line code to creat a dialogbox.Just button press click listener,Dialog onCreateDialog and cancel button listener.
here i put full code .just check it
public class FeedbackFormusingInsideDialogBox extends Activity {
static final int CUSTOM_DIALOG_ID = 0;
Button customDialog_Dismiss;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button buttonStartDialog = (Button)findViewById(R.id.startdialog);
buttonStartDialog.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
showDialog(CUSTOM_DIALOG_ID);
}
});
}
private Button.OnClickListener customDialog_DismissOnClickListener = new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
dismissDialog(CUSTOM_DIALOG_ID);
}
};
@Override
protected Dialog onCreateDialog(int id) {
// TODO Auto-generated method stub
Dialog dialog = null;;
switch(id) {
case CUSTOM_DIALOG_ID:
dialog = new Dialog(this);
dialog.setContentView(R.layout.dialogbox);
dialog.setTitle("Feed Back Form");
customDialog_Dismiss = (Button)dialog.findViewById(R.id.button2);
customDialog_Dismiss.setOnClickListener(customDialog_DismissOnClickListener);
break;
}
return dialog;
}
}
Result :
I’m ecstatic I discovered your website and blogs.
ReplyDeleteroot android phone
Web Designing
ReplyDeletei liked really bookmarked sharing
How to download this Android Application
ReplyDeleteThere is link name as download full source code
ReplyDeleteAwesome Blog. Thanks. Do keep posting such good blogs. Thanks for sharing Informative posts.Mobile App Cross Platform Development
ReplyDeletehgg
ReplyDeleteI am a beginner and i have a doubt on where exactly will the content be going once the send button is clicked...??
ReplyDeleteI am also a beginner and i have a doubt on where exactly will the content be going once the send button is clicked...??
ReplyDeleteUiPath Training in Bangalore by myTectra is one the best UiPath Training. myTectra is the market leader in providing Robotic Process Automation on UiPath
ReplyDeleteui path training in bangalore
thanks for sharing this information
ReplyDeleteBlue Prism Training in Bangalore
Blue Prism Training in BTM
RPA Training in Bangalore
RPA Training in BTM
Artificial Intelligence training in Bangalore
Artificial Intelligence training in BTM
Great blog.Keep going.
ReplyDeleteJava training in Chennai
Java training in Bangalore
Java training in Hyderabad
Java Training in Coimbatore
Java Online Training