Skip to content

Instantly share code, notes, and snippets.

@ShahoodulHassan
Created June 23, 2018 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShahoodulHassan/38c647faa6435b9b8c82bb5c3d1fd822 to your computer and use it in GitHub Desktop.
Save ShahoodulHassan/38c647faa6435b9b8c82bb5c3d1fd822 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/display_name" />
<EditText
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/value" />
<EditText
android:id="@+id/value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/value" />
<EditText
android:id="@+id/value2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/value" />
<EditText
android:id="@+id/value3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/value" />
<EditText
android:id="@+id/value4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/value" />
<EditText
android:id="@+id/value5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/value" />
<EditText
android:id="@+id/value6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/value" />
<EditText
android:id="@+id/value7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/value" />
<EditText
android:id="@+id/value8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" />
</LinearLayout>
</LinearLayout>
</ScrollView>
import android.app.ActionBar;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.Toast;
public class SampleDialogFragment extends DialogFragment implements
DialogInterface.OnClickListener {
private View form = null;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
form =
getActivity().getLayoutInflater()
.inflate(R.layout.dialog, null);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
return (builder.setTitle(R.string.dlg_title).setView(form)
.setPositiveButton(android.R.string.ok, this)
.setNegativeButton(android.R.string.cancel, null).create());
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
super.onViewCreated(view, savedInstanceState);
}
@Override
public void onClick(DialogInterface dialog, int which) {
String template = getActivity().getString(R.string.toast);
EditText name = (EditText) form.findViewById(R.id.title);
EditText value = (EditText) form.findViewById(R.id.value);
String msg =
String.format(template, name.getText().toString(),
value.getText().toString());
Toast.makeText(getActivity(), msg, Toast.LENGTH_LONG).show();
}
@Override
public void onDismiss(DialogInterface unused) {
super.onDismiss(unused);
Log.d(getClass().getSimpleName(), "Goodbye!");
}
@Override
public void onCancel(DialogInterface unused) {
super.onCancel(unused);
Toast.makeText(getActivity(), R.string.back, Toast.LENGTH_LONG).show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment