Advertisement
Guest User

Untitled

a guest
Sep 1st, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1.         mainEditText.addTextChangedListener(new TextWatcher() {
  2.             @Override
  3.             public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {}
  4.  
  5.             @Override
  6.             public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {}
  7.  
  8.             @Override
  9.             public void afterTextChanged(Editable editable) {
  10.                 if (editable.length() > 1 && (editable.charAt(editable.length() - 1) == '\n')) {
  11.                     String name = mainEditText.getText().toString().trim();
  12.                     if (name.length() > 0)
  13.                         updateNames(name);
  14.                 }
  15.             }
  16.         });
  17.  
  18.     private void updateNames(String name) {
  19.         name = capitilise(name);
  20.         // Take what was typed into the EditText and use in TextView
  21.         mainTextView.setText(name + " is learning Android development bitches!");
  22.  
  23.         // Also add that value to the list shown in the Listview
  24.         mNameList.add(name);
  25.         mArrayAdapter.notifyDataSetChanged();
  26.  
  27.         // Remove content from EditText
  28.         mainEditText.setText("");
  29.  
  30.         // The text you'd like to share has changed, and you need to update
  31.         setShareIntent();
  32.     }
  33.  
  34.  
  35.     @Override
  36.     public void onClick(View view) {
  37.         String name = mainEditText.getText().toString().trim();
  38.         if (name.length() > 0) {
  39.             updateNames(name);
  40.         }
  41.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement