Advertisement
Guest User

Untitled

a guest
Sep 19th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. public class VehicleInfoActivity extends Activity {
  2.  
  3. private EditText mLicence;
  4.  
  5.  
  6. @Override
  7. public void onCreate(Bundle savedInstanceState) {
  8. super.onCreate(savedInstanceState);
  9. setContentView(R.layout.activity_vehicle_info);
  10.  
  11. mLicence = (EditText) findViewById(R.id.licensePlate);
  12.  
  13. mLicence.addTextChangedListener(new TextWatcher() {
  14. @Override
  15. public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  16. }
  17.  
  18. @Override
  19. public void onTextChanged(CharSequence s, int start, int before, int count) {
  20. }
  21.  
  22. @Override
  23. public void afterTextChanged(Editable s) {
  24. String pattern = "X000XX000";
  25.  
  26. if (text.length() < pattern.length() && pattern.charAt(text.length()) == '0') {
  27. mLicence.setInputType(InputType.TYPE_CLASS_PHONE);
  28. } else {
  29. mLicence.setInputType(InputType.TYPE_CLASS_TEXT);
  30. }
  31. }
  32. });
  33. }
  34. }
  35.  
  36. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  37. xmlns:tools="http://schemas.android.com/tools"
  38. android:layout_width="match_parent"
  39. android:layout_height="match_parent"
  40. tools:context=".activities.VehicleInfoActivity">
  41.  
  42. <EditText
  43. android:id="@+id/licensePlate"
  44. android:layout_width="150pt"
  45. android:layout_height="wrap_content"
  46. android:layout_alignParentLeft="true"
  47. android:layout_alignParentStart="true"
  48. />
  49.  
  50. </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement