Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. public class GetUserNameDialogFragment extends DialogFragment {
  2.  
  3. final String TAG = "GetUserNameDialog";
  4. @Override
  5. public Dialog onCreateDialog(Bundle savedInstanceState) {
  6.  
  7. AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.MyAlertDialogStyle);
  8. //TODO getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
  9.  
  10. LayoutInflater inflater = getActivity().getLayoutInflater();
  11. final View sunburst =inflater.inflate(R.layout.dialog_user_name, null);
  12. builder.setView(sunburst);
  13.  
  14.  
  15. builder.setCancelable(false)
  16. .setPositiveButton("Let's go!", new DialogInterface.OnClickListener() {
  17. public void onClick(DialogInterface dialog, int id) {
  18.  
  19. Log.wtf(TAG, "button press");
  20. EditText name = (EditText) sunburst.findViewById(R.id.nameEditText);
  21. String userName = name.getText().toString().trim();
  22. //TODO needs to be validated
  23. SharedPreferences sharedPref = getActivity().getSharedPreferences("userDetails", Context.MODE_PRIVATE);
  24. SharedPreferences.Editor editor = sharedPref.edit();
  25. editor.putString("userName", userName );
  26. editor.commit();
  27. }
  28. });
  29. // Create the AlertDialog object and return it
  30. return builder.create();
  31. }
  32. }
  33.  
  34. <?xml version="1.0" encoding="utf-8"?>
  35. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  36. xmlns:app="http://schemas.android.com/apk/res-auto"
  37. android:orientation="vertical"
  38. android:layout_width="wrap_content"
  39. android:layout_height="wrap_content">
  40. <ImageView
  41. android:layout_width="match_parent"
  42. android:layout_height="wrap_content"
  43. android:scaleType="fitCenter"
  44. android:adjustViewBounds="true"
  45. app:srcCompat="@drawable/ic_ball_sunburst_classic"
  46. android:background="@color/colorAccent"
  47. />
  48. <LinearLayout
  49. android:layout_width="250dp"
  50. android:paddingLeft="16dp"
  51. android:paddingRight="16dp"
  52. android:layout_height="125dp">
  53. <EditText
  54. android:id="@+id/nameEditText"
  55. android:layout_width="match_parent"
  56. android:layout_height="wrap_content"
  57. android:paddingTop="8dp"
  58. android:hint="Enter your first name"/>
  59. </LinearLayout>
  60. </LinearLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement