Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法在edittext中设置自定义图像_Android_Android Edittext_Textwatcher - Fatal编程技术网

Android 无法在edittext中设置自定义图像

Android 无法在edittext中设置自定义图像,android,android-edittext,textwatcher,Android,Android Edittext,Textwatcher,我试图得到与中所示相同的结果。但没有任何图像被设置。此外,我必须点击每个编辑文本来键入一个数字。输入“上一个”(maxLength=1)时,我希望光标移动到下一个edittext。“star1”是带有星星的图像,“empty”是没有星星的图像。如果有人能告诉我我做错了什么,那将非常有帮助 activity\u main 主要活动 公共类MainActivity扩展了活动{ 编辑文本ET1、ET2、ET3、ET4; @凌驾 创建时受保护的void(Bundle savedInstanceSta

我试图得到与中所示相同的结果。但没有任何图像被设置。此外,我必须点击每个编辑文本来键入一个数字。输入“上一个”(maxLength=1)时,我希望光标移动到下一个edittext。“star1”是带有星星的图像,“empty”是没有星星的图像。如果有人能告诉我我做错了什么,那将非常有帮助

activity\u main
主要活动
公共类MainActivity扩展了活动{
编辑文本ET1、ET2、ET3、ET4;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ET1=(EditText)findViewById(R.id.ET1);
ET2=(EditText)findViewById(R.id.ET2);
ET3=(EditText)findViewById(R.id.ET3);
ET4=(EditText)findViewById(R.id.ET4);
}//onCreate结束
私有void handleEdittextListner(){
试一试{
ET1.addTextChangedListener(新的TextWatcher(){
@凌驾
public void onTextChanged(字符序列、int start、int before、int count){
//TODO自动生成的方法存根
}
@凌驾
更改前的公共无效(字符序列、整数开始、整数计数、,
整数后){
//TODO自动生成的方法存根
}
@凌驾
公共无效后文本已更改(可编辑){
//TODO自动生成的方法存根
if(ET1.getText().toString().trim().length()==1){
ET1.clearFocus();
ET2.requestFocus();
ET1.挫折资源(R.drawable.star1);
}
}
});
ET2.addTextChangedListener(新的TextWatcher(){
@凌驾
public void onTextChanged(字符序列、int start、int before、int count){
//TODO自动生成的方法存根
}
@凌驾
更改前的公共无效(字符序列、整数开始、整数计数、,
整数后){
//TODO自动生成的方法存根
}
@凌驾
公共无效后文本已更改(可编辑){
if(ET2.getText().toString().trim().length()==1){
ET2.clearFocus();
ET3.requestFocus();
ET2.挫折资源(R.drawable.star1);
}
}
});
ET3.addTextChangedListener(新的TextWatcher(){
@凌驾
public void onTextChanged(字符序列、int start、int before、int count){
}
@凌驾
更改前的公共无效(字符序列、整数开始、整数计数、,
整数后){
}
@凌驾
公共无效后文本已更改(可编辑){
if(ET3.getText().toString().trim().length()==1){
//ET1.clearFocus();
ET3.clearFocus();
ET4.requestFocus();
ET3.挫折资源(R.drawable.star1);
}
}
});
ET4.addTextChangedListener(新的TextWatcher(){
@凌驾
public void onTextChanged(字符序列、int start、int before、int count){
}
@凌驾
更改前的公共无效(字符序列、整数开始、整数计数、,
整数后){
}
@凌驾
公共无效后文本已更改(可编辑){
if(ET4.getText().toString().trim().length()==1){
ET4.挫折资源(R.drawable.star1);
//隐藏键盘
InputMethodManager imm=
(InputMethodManager)getSystemService(Context.INPUT\u方法\u服务);
imm.hideSoftInputFromWindow(ET4.getWindowToken(),0);
}
}
});
this.ET2.setOnKeyListener(新视图.OnKeyListener()
{
@凌驾
公共布尔onKey(View paramView、int paramInt、KeyEvent paramKeyEvent){
//TODO自动生成的方法存根
if((paramKeyEvent.getAction()=KeyEvent.ACTION_DOWN)&&&(paramInt==67)&&(MainActivity.this.ET2.getText().length()=0)){
ET1.requestFocus();
ET1.挫折资源(R.可提取.空);
ET1.setText(“”);
}
返回false;
}
});
this.ET3.setOnKeyListener(新视图.OnKeyListener()
{
公共布尔onKey(View paramView、int paramInt、KeyEvent paramKeyEvent)
{
if((paramKeyEvent.getAction()=KeyEvent.ACTION_DOWN)&&&(paramInt==67)&&(MainActivity.this.ET3.getText().length()=0)){
ET2.requestFocus();
ET2.挫折资源(R.可提取.空);
ET2.setText(“”);
}
返回false;
}
});
this.ET4.setOnKeyListener(新视图.OnKeyListener()
{
公共布尔onKey(View paramView、int paramInt、KeyEvent paramKeyEvent)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/white"
    android:orientation="vertical" >
android:textColor="@android:color/white" 
EditText ET1, ET2, ET3, ET4;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ET1 = (EditText)findViewById(R.id.ET1);
    ET2 = (EditText)findViewById(R.id.ET2);
    ET3 = (EditText)findViewById(R.id.ET3);
    ET4 = (EditText)findViewById(R.id.ET4);

    ET1.addTextChangedListener(new TextWatcher() {

        public void afterTextChanged(Editable s) {
            if(s.length() == 1){
                ET1.setBackgroundResource(R.drawable.star1);
                if(ET2.requestFocus()){
                    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                }
            }
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // TODO Auto-generated method stub
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub  
        }
    });

    ET2.addTextChangedListener(new TextWatcher() {

        public void afterTextChanged(Editable s) {
            if(s.length() == 1){
                ET2.setBackgroundResource(R.drawable.star1);
                if(ET3.requestFocus()){
                    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                }
            }
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // TODO Auto-generated method stub
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub  
        }
    });

    ET3.addTextChangedListener(new TextWatcher() {

        public void afterTextChanged(Editable s) {
            if(s.length() == 1){
                ET3.setBackgroundResource(R.drawable.star1);
                if(ET4.requestFocus()){
                    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                }
            }
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // TODO Auto-generated method stub
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub  
        }
    });

    ET4.addTextChangedListener(new TextWatcher() {

        public void afterTextChanged(Editable s) {
            if(s.length() == 1){
                ET3.setBackgroundResource(R.drawable.star1);
                InputMethodManager imm =
                        (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(ET4.getWindowToken(), 0);
            }
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // TODO Auto-generated method stub
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub  
        }
    });
}
<FrameLayout 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:background="@drawable/round" >
    <EditText 
        android:id="@+id/ET1" 
        android:layout_height="70dp" 
        android:layout_width="70dp" 
        android:singleLine="true"
        android:maxLength="1"
        android:inputType="number">
        </EditText>
    </FrameLayout>