User Interface. EditText

În cadrul acestui tutorial vei învăța cum se utilizează EditText pentru a prelua input de la utilizator. De asemenea vei afla cum poate fi customizat acest control.

ui_index

1. Adăugare control în xml-ul asignat layout-ului

<EditText

android:id="@+id/editTextSimple"

android:layout_height="wrap_content"

android:layout_width="match_parent">

</EditText>

2. Preluare valoare în mod programatic

EditText simpleEditText = (EditText) findViewById(R.id.editTextSimple);
String strValue = simpleEditText.getText().toString();

3. Evenimente asociate

  • setOnClickListener() – utilizatorul efectuază un “click” asupra controlului
  • setOnLongClickListener() – “long-click”
  • setOnKeyListener()  – utilizatorul selectează o tastă din cadrul tastaturii virtuale
  • setOnFocusChangedListener() – modificare focus
final EditText simpleEditText = (EditText) findViewById(R.id.editTextSimple);

simpleEditText.setOnFocusChangeListener(new OnFocusChangeListener() {

public void onFocusChange(View v, boolean hasFocus) {

String strValue = simpleEditText.getText().toString();

Log.d(DEBUG_TAG, "User set EditText value to " + strValue);

}

});

4. Tipuri de input-uri

android:inputType="phone"
  • none
  • text
  • textCapCharacters
  • textCapWords
  • textCapSentences
  • textAutoCorrect
  • textAutoComplete
  • textMultiLine
  • textImeMultiLine
  • textNoSuggestions
  • textUri
  • textEmailAddress
  • textEmailSubject
  • textShortMessage
  • textLongMessage
  • textPersonName
  • textPostalAddress
  • textPassword
  • textVisiblePassword
  • textWebEditText
  • textFilter
  • textPhonetic
  • textWebEmailAddress
  • textWebPassword
  • number
  • numberSigned
  • numberDecimal
  • numberPassword
  • phone
  • datetime
  • date
  • time

5. Setare sugestie

android:hint="@string/parola"
Advertisements
User Interface. EditText

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s