Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GetUserNameDialogFragment extends DialogFragment {
- final String TAG = "GetUserNameDialog";
- @Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.MyAlertDialogStyle);
- //TODO getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
- LayoutInflater inflater = getActivity().getLayoutInflater();
- final View sunburst =inflater.inflate(R.layout.dialog_user_name, null);
- builder.setView(sunburst);
- builder.setCancelable(false)
- .setPositiveButton("Let's go!", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- Log.wtf(TAG, "button press");
- EditText name = (EditText) sunburst.findViewById(R.id.nameEditText);
- String userName = name.getText().toString().trim();
- //TODO needs to be validated
- SharedPreferences sharedPref = getActivity().getSharedPreferences("userDetails", Context.MODE_PRIVATE);
- SharedPreferences.Editor editor = sharedPref.edit();
- editor.putString("userName", userName );
- editor.commit();
- }
- });
- // Create the AlertDialog object and return it
- return builder.create();
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- android:orientation="vertical"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
- <ImageView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:scaleType="fitCenter"
- android:adjustViewBounds="true"
- app:srcCompat="@drawable/ic_ball_sunburst_classic"
- android:background="@color/colorAccent"
- />
- <LinearLayout
- android:layout_width="250dp"
- android:paddingLeft="16dp"
- android:paddingRight="16dp"
- android:layout_height="125dp">
- <EditText
- android:id="@+id/nameEditText"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:paddingTop="8dp"
- android:hint="Enter your first name"/>
- </LinearLayout>
- </LinearLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement