2011-01-04 28 views

Respuesta

148

Si marca los documentos para EditText, encontrará el método setText(). Se necesita String y TextView.BufferType. Por ejemplo:

EditText editText = (EditText)findViewById(R.id.edit_text); 
editText.setText("Google is your friend.", TextView.BufferType.EDITABLE); 
+4

'EditText.BufferType.EDITABLE'? – sll

+2

No, 'EditText' extiende' TextView'; 'TextView.BufferType.EDITABLE' es la constante correcta. – kcoppock

+2

Lo que podría confundir a un novato es que setText realmente toma una CharSequence y un BufferType. Por lo tanto, es útil recordar que Strings es el – Avatar33

1

Es necesario:

  1. declarar la EditText in the xml file
  2. Encuentra la EditText en la actividad
  3. Ajuste el texto en el EditText
2

Uso +, el operador de concatenación de cadenas:

ed = (EditText) findViewById (R.id.box); 
    int x = 10; 
    ed.setText(""+x); 

o utilizar

String.valueOf(int): 
ed.setText(String.valueOf(x)); 

o uso

Integer.toString(int): 
ed.setText(Integer.toString(x)); 
0
EditText editText = (EditText)findViewById(R.id.edit_text); 
editText.setText("Google is your friend.", TextView.BufferType.EDITABLE); 

no ser demasiado técnico, y estoy seguro de que sea lo bastante como yo, pero es 'editable'.

1

Puede establecer android:text="your text";

<EditText 
    android:id="@+id/editTextName" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/intro_name"/> 
1
String text = "Example"; 
EditText edtText = (EditText) findViewById(R.id.edtText); 
edtText.setText(text); 

Compruébelo usted mismo EditText sólo aceptan valores de cadena si es necesario convertir a cadena.

Si int, double valor, larga, hacer:

String.value(value); 
0
public boolean checkUser(String email, String password) { 

    // array of columns to fetch 
    String[] columns = { 
      COLUMN_USER_ID 
    }; 
    SQLiteDatabase db = this.getReadableDatabase(); 

    // selection criteria 
    String selection = COLUMN_USER_EMAIL + " = ?" + " AND " + COLUMN_USER_PASSWORD + " = ?"; 

    //selection arguments 
    String[] selectionArgs = {email, password}; 
    Cursor cursor = db.query(TABLE_USER, //Table to query 
      columns,      //columns to return 
      selection,     //columns for the WHERE clause 
      selectionArgs,    //The values for the WHERE clause 
      null,      //group the rows 
      null,      //filter by row groups 
      null);      //The sort order 

    int cursorCount = cursor.getCount(); 
    cursor.close(); 
    db.close(); 
    if (cursorCount > 0) { 
     return true; 
    } 
    return false; 
} 
Cuestiones relacionadas