获取服务

时间:2016-05-13 03:54:18

标签: java android service android-edittext

目前,我正在为我的公司执行任务,我需要在其中实施密码。此密码实际上是Service。事先,我测试我的密码,只是使用一个简单的android项目(该项目是Activity),我可以完成这个,然后我使用相同的方法在ServiceService虽然我的EditText UI已经填充了我在键盘上按下的值,但无法获取EditText值。以下是代码:

PasswordView.java:

import GetAsteriskForPassword;
import Log;
import InstanceManager;
import R;
import android.graphics.Typeface;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;

public class PasswordView extends FrameLayout {

    private View mBaseView;
    private EditText mPassword;
    private TextView mPasswordTitle;
    private final String mActualPass = "027";


    public PasswordView() {
        super(InstanceManager.getService());
        init();
    }

    /**
     * initialize. called from constructor.
     */
    private void init() {
        LayoutInflater inflater = LayoutInflater.from(getContext());

        mBaseView = inflater.inflate(R.layout.menu_password, this, false);
        addView(mBaseView);
        Log.i("paswordView", "==== paswordView");

        mPasswordTitle = (TextView) findViewById(R.id.lblPassword);
        mPassword = (EditText) findViewById(R.id.txtPassword);

        setPasswordParameter();
    }

    private void setPasswordParameter() {
        final Typeface typeface = Typeface.createFromFile("LCFONT_LATIN");
        mPasswordTitle.setText("Input Password");
        mPasswordTitle.setTypeface(typeface);
        mPassword.setTransformationMethod(new GetAsteriskForPassword());
        mPassword.setInputType(EditorInfo.TYPE_NULL);
    }

    public void addListenerOnButton() {
        mPassword.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) {
                Log.i("paswordView", "==== afterTextChanged");
                setTextValue(s);
            }

        });
    }

    private void setTextValue(final Editable s) {
        Log.i("paswordView", "==== setTextValue");
        if (s.length() < 3) {
            // do nothing
        } else {
            if (mActualPass.equals(s.toString())) {
                MenuWindow.getInstance().open();
            }
            PasswordWindow.getInstance().close();
        }
    }
}

当我输入EditText时,该值会显示在UI中,但是函数afterTextChanged(Editable s)根本就没有运行。当我输入UI时,日志没有出现。

这里的任何人都知道如何纠正这个问题? 谢谢!

0 个答案:

没有答案