Skip to content

Instantly share code, notes, and snippets.

@gordinmitya
Created February 28, 2017 19:54
Show Gist options
  • Save gordinmitya/55a5bbca83577396dd6e04531720c4a0 to your computer and use it in GitHub Desktop.
Save gordinmitya/55a5bbca83577396dd6e04531720c4a0 to your computer and use it in GitHub Desktop.
LayoutInflater factory = LayoutInflater.from(this); // this это context
// final - для того чтобы использовать его в OnClickListener()
final View alertView = factory.inflate(R.layout.layout_add_note, null);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(alertView);
builder.setTitle(R.string.alert_title_add);
builder.setNegativeButton(R.string.alert_cancel, null);
builder.setPositiveButton(R.string.menu_add, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
EditText editTextNote = (EditText) alertView.findViewById(R.id.editTextNote);
EditText editTextNoteTitle = (EditText) alertView.findViewById(R.id.editTextNoteTitle);
addNote(editTextNoteTitle.getText().toString() ,editTextNote.getText().toString());
dataUpdated();
}
});
builder.show();
// layout_add_note
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:id="@+id/editTextNoteTitle"
android:inputType="textEmailAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="4dp"
android:hint="@string/title" />
<EditText
android:id="@+id/editTextNote"
android:inputType="text|textMultiLine"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="4dp"
android:hint="@string/note" />
</LinearLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment