Created
March 19, 2014 18:19
-
-
Save Swimburger/9647935 to your computer and use it in GitHub Desktop.
Custom alert dialog example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout | |
xmlns:tools="http://schemas.android.com/tools" | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:padding="@dimen/activity_horizontal_margin"> | |
<TextView | |
android:textAppearance="@android:style/TextAppearance.Large" | |
android:layout_alignBottom="@+id/spinnerModule" | |
android:id="@+id/module" | |
android:layout_marginRight="8dp" | |
android:text="@string/module" | |
android:layout_width="wrap_content" | |
android:layout_height="48dp" | |
android:gravity="center"/> | |
<Spinner | |
android:layout_marginTop="8dp" | |
tools:listitem="@android:layout/simple_spinner_dropdown_item" | |
android:id="@id/spinnerModule" | |
android:layout_toRightOf="@id/module" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="24dp"/> | |
<TextView | |
android:layout_below="@id/spinnerModule" | |
android:layout_alignParentRight="true" | |
android:id="@+id/onTwenty" | |
android:text="/20" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content"/> | |
<EditText | |
android:hint="@string/score_module" | |
android:id="@+id/txtScore" | |
android:layout_alignBaseline="@id/onTwenty" | |
android:layout_toLeftOf="@id/onTwenty" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" | |
android:inputType="numberDecimal"/> | |
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void showDialog() { | |
LayoutInflater li = LayoutInflater.from(getActivity()); | |
View promptsView = li.inflate(R.layout.dialog_wijzig_score, null); | |
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( | |
getActivity()); | |
// set prompts.xml to alertdialog builder | |
alertDialogBuilder.setView(promptsView); | |
// set dialog message | |
alertDialogBuilder | |
.setTitle("Score student") | |
.setCancelable(false) | |
.setPositiveButton("Bewaren", | |
new DialogInterface.OnClickListener() { | |
public void onClick(DialogInterface dialog, int id) { | |
//input | |
} | |
}) | |
.setNegativeButton("Annuleren", | |
new DialogInterface.OnClickListener() { | |
public void onClick(DialogInterface dialog, int id) { | |
dialog.cancel(); | |
} | |
} | |
); | |
// create alert dialog | |
AlertDialog alertDialog = alertDialogBuilder.create(); | |
// show it | |
alertDialog.show(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment