Estoy tratando de crear un string
que me arroje una construcción de RFC mexicano con Android Studio y la clase TextWatcher
, en donde necesito la primera letra y primer vocal del apellido paterno, primera letra del apellido materno y primera letra del nombre.
Ejemplo: Diana Alvarez Lopez
Salida: AALD
Este es mi código:
public class MainActivity extends Activity {
private EditText nombreEditText, apellidoEditText, apellidomatEditiText;
private TextView textView;
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
private GoogleApiClient client;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
nombreEditText = (EditText) findViewById(R.id.nombre_et);
String[] arr = nombreEditText.split(" ", 2);
apellidoEditText = (EditText) findViewById(R.id.apellido_et);
textView = (TextView) findViewById(R.id.construccionRFC);
textView.setVisibility(View.VISIBLE);
// Set Text Watcher listener
nombreEditText.addTextChangedListener(rfcWatcher);
apellidoEditText.addTextChangedListener(rfcWatcher);
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
private final TextWatcher elrfcWatcher = new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
textView.setVisibility(View.VISIBLE);
}
public void afterTextChanged(Editable s) {
textView.setText("" + nombreEditText.getText() + apellidoEditText.getText());
}
};
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
public Action getIndexApiAction() {
Thing object = new Thing.Builder()
.setName("Main Page") // TODO: Define a title for the content shown.
.setUrl(Uri.parse("http://[ENTER-YOUR-URL-HERE]")) // TODO: Make sure this auto-generated URL is correct.
.build();
return new Action.Builder(Action.TYPE_VIEW)
.setObject(object)
.setActionStatus(Action.STATUS_TYPE_COMPLETED)
.build();
}
@Override
public void onStart() {
super.onStart();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client.connect();
AppIndex.AppIndexApi.start(client, getIndexApiAction());
}
@Override
public void onStop() {
super.onStop();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
AppIndex.AppIndexApi.end(client, getIndexApiAction());
client.disconnect();
}
}