J'essaie d'obtenir le même résultat que celui indiqué dans here. Mais aucune image ne se prépare. De plus, je dois cliquer sur chaque edittext pour taper un nombre. Je veux que le curseur se déplace au prochain edittext quand le précédent est entré (maxLength = 1). Le "star1" est l'image avec l'étoile et "vide" est l'image sans étoile. Ce serait vraiment utile si quelqu'un peut me dire ce que j'ai fait de mal.impossible de définir une image personnalisée dans edittext
activity_main
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="40dp" >
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<EditText
android:id="@+id/ET1"
android:layout_height="70dp"
android:layout_width="70dp"
android:singleLine="true"
android:maxLength="1"
android:inputType="number"
android:background="@drawable/round" >
</EditText>
<EditText
android:id="@+id/ET2"
android:layout_height="70dp"
android:layout_width="70dp"
android:singleLine="true"
android:maxLength="1"
android:inputType="number"
android:background="@drawable/round" >
</EditText>
<EditText
android:id="@+id/ET3"
android:layout_height="70dp"
android:layout_width="70dp"
android:singleLine="true"
android:maxLength="1"
android:inputType="number"
android:background="@drawable/round" >
</EditText>
<EditText
android:id="@+id/ET4"
android:layout_height="70dp"
android:layout_width="70dp"
android:singleLine="true"
android:maxLength="1"
android:inputType="number"
android:background="@drawable/round" >
</EditText>
</TableRow>
</TableLayout>
</LinearLayout>
Main Activity
public class MainActivity extends Activity {
\t
\t EditText ET1, ET2, ET3, ET4;
\t @Override
\t protected void onCreate(Bundle savedInstanceState) {
\t \t super.onCreate(savedInstanceState);
\t \t setContentView(R.layout.activity_main);
\t \t
\t \t ET1 = (EditText)findViewById(R.id.ET1);
\t \t ET2 = (EditText)findViewById(R.id.ET2);
\t \t ET3 = (EditText)findViewById(R.id.ET3);
\t \t ET4 = (EditText)findViewById(R.id.ET4);
\t } // onCreate ends
\t
\t
\t private void handleEdittextListner(){
try {
ET1.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
\t \t \t \t @Override
\t \t \t \t public void afterTextChanged(Editable s) {
\t \t \t \t \t // TODO Auto-generated method stub
\t \t \t \t \t if(ET1.getText().toString().trim().length()==1){
\t \t \t \t \t \t
ET1.clearFocus();
ET2.requestFocus();
ET1.setBackgroundResource(R.drawable.star1);
}
\t \t \t \t }
});
ET2.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
if(ET2.getText().toString().trim().length()==1){
ET2.clearFocus();
ET3.requestFocus();
ET2.setBackgroundResource(R.drawable.star1);
}
}
});
ET3.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
if(ET3.getText().toString().trim().length()==1){
//ET1.clearFocus();
ET3.clearFocus();
ET4.requestFocus();
ET3.setBackgroundResource(R.drawable.star1);
}
}
});
ET4.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
if(ET4.getText().toString().trim().length()==1){
ET4.setBackgroundResource(R.drawable.star1);
//Hide keyboard
InputMethodManager imm =
(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(ET4.getWindowToken(), 0);
}
}
});
this.ET2.setOnKeyListener(new View.OnKeyListener()
{
\t \t \t \t @Override
\t \t \t \t public boolean onKey(View paramView, int paramInt, KeyEvent paramKeyEvent) {
\t \t \t \t \t // TODO Auto-generated method stub
\t \t \t \t \t if ((paramKeyEvent.getAction() == KeyEvent.ACTION_DOWN)&&(paramInt == 67) && (MainActivity.this.ET2.getText().length() == 0)){
ET1.requestFocus();
ET1.setBackgroundResource(R.drawable.empty);
ET1.setText("");
}
\t \t \t \t \t return false;
\t \t \t \t }
});
this.ET3.setOnKeyListener(new View.OnKeyListener()
{
public boolean onKey(View paramView, int paramInt, KeyEvent paramKeyEvent)
{
if ((paramKeyEvent.getAction() == KeyEvent.ACTION_DOWN)&&(paramInt == 67) && (MainActivity.this.ET3.getText().length() == 0)){
ET2.requestFocus();
ET2.setBackgroundResource(R.drawable.empty);
ET2.setText("");
}
return false;
}
});
this.ET4.setOnKeyListener(new View.OnKeyListener()
{
public boolean onKey(View paramView, int paramInt, KeyEvent paramKeyEvent)
{
if ((paramKeyEvent.getAction() == KeyEvent.ACTION_DOWN)&&(paramInt == 67) && (MainActivity.this.ET4.getText().length() == 0)){
ET3.requestFocus();
ET3.setBackgroundResource(R.drawable.empty);
ET3.setText("");
}
return false;
}
});
} catch (Exception e) {
e.toString();
}
}
\t
} // Activity ends
Vous souhaitez utiliser cette disposition pour la saisie du mot de passe? – zkminusck
Cette disposition ou tout autre. Je veux juste placer l'image faite sur commande au lieu de. (Point) dans tel 4 EditText –
Je suis capable de changer le point en "*" en utilisant PasswordTransformationMethod. Mais je veux mettre l'image au lieu de "*" –