Adding a Layout file into DialogBox

public void allertDialog()
{
AlertDialog.Builder alert = new AlertDialog.Builder(this);
LayoutInflater factory = LayoutInflater.from(this);

//LayoutInflater is used to adapot a layout file into view object
alert.setTitle(“Title”);
alert.setMessage(“Message”);
//alertview is a xml file which should be created
final View textEntryView = factory.inflate(R.layout.alertview, null);
alert.setView(textEntryView);

//To use the edittext

final EditText diagtare=(EditText)textEntryView.findViewById(R.id.diagtare);
final EditText diagtruckno=(EditText)textEntryView.findViewById(R.id.diagtruckno);

//xml file is been added to the dialogbox
alert.setPositiveButton(“Ok”, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//action to do
}
});

alert.setNegativeButton(“Cancel”, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//action to do
}
});
alert.show();

}

alertview.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<TableLayout
xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
android:layout_width=”match_parent”
android:layout_height=”wrap_content”>
<TableRow >
<TextView
android:layout_width=”100dp”
android:layout_height=”wrap_content”
android:text=”Truck No”
/>
<EditText
android:layout_width=”150dp”
android:layout_height=”wrap_content”
android:id=”@+id/diagtruckno”
/>
</TableRow>
<TableRow >
<TextView
android:layout_width=”100dp”
android:layout_height=”wrap_content”
android:text=”Tare”/>
<EditText
android:layout_width=”150dp”
android:layout_height=”wrap_content”
android:id=”@+id/diagtare”
/>
</TableRow>

</TableLayout>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s