Pages

Jumat, 05 Agustus 2011

How to create FeedBack Form inside of the customDialogBox?

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.
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
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 :




0 komentar:

Posting Komentar