Advertisement
Guest User

Untitled

a guest
Apr 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.04 KB | None | 0 0
  1. package com.example.rubel.teammate;
  2.  
  3. import android.app.AlertDialog;
  4. import android.content.DialogInterface;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.os.Bundle;
  7. import android.text.Editable;
  8. import android.text.InputType;
  9. import android.util.Log;
  10. import android.widget.EditText;
  11.  
  12. public class MainActivity extends AppCompatActivity {
  13.     private String m_Text = "";
  14.  
  15.     @Override
  16.     protected void onCreate(Bundle savedInstanceState) {
  17.         super.onCreate(savedInstanceState);
  18.         setContentView(R.layout.activity_main);
  19.  
  20. //        AlertDialog.Builder alert = new AlertDialog.Builder(this);
  21. //
  22. //        alert.setTitle("Registration");
  23.  
  24. //        alert.setMessage("Server Name:");
  25. //        // Set an EditText view to get user input
  26. //        final EditText servername = new EditText(this);
  27. //        alert.setView(servername);
  28. //
  29. //        alert.setMessage("User Name:");
  30. //        // Set an EditText view to get user input
  31. //        final EditText username = new EditText(this);
  32. //        alert.setView(username);
  33. //
  34. //        alert.setMessage("Password:");
  35. //        // Set an EditText view to get user input
  36. //        final EditText password = new EditText(this);
  37. //        //alert.setView(password);
  38. //
  39. //        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
  40. //            public void onClick(DialogInterface dialog, int whichButton) {
  41. //                String value1 = servername.getText().toString();
  42. //                String value2 = username.getText().toString();
  43. //                String value3 = password.getText().toString();
  44. //                // Do something with value!
  45. //            }
  46. //        });
  47. //
  48.        
  49.        
  50.        
  51.        
  52.          alertOneButton();
  53.          String name = utils.getPreference(getApplicationContext(),"username");
  54.          Log.d("name",name);
  55.  
  56.  
  57.     }
  58.  
  59.  
  60.     public void alertOneButton() {
  61.  
  62.         AlertDialog.Builder builder = new AlertDialog.Builder(this);
  63.         builder.setTitle("Title");
  64.  
  65. // Set up the input
  66.         final EditText input = new EditText(this);
  67. // Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
  68.         //input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
  69.         input.setInputType(InputType.TYPE_CLASS_TEXT);
  70.         builder.setView(input);
  71.  
  72. // Set up the buttons
  73.         builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
  74.             @Override
  75.             public void onClick(DialogInterface dialog, int which) {
  76.                 m_Text = input.getText().toString();
  77.                 //Log.d("Name", m_Text);
  78.                 utils.savePreference(getApplicationContext(),"username",m_Text);
  79.             }
  80.         });
  81.         builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
  82.             @Override
  83.             public void onClick(DialogInterface dialog, int which) {
  84.                 dialog.cancel();
  85.             }
  86.         });
  87.  
  88.         builder.show();
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement