package com.example.angluswang.mobilesafe.activity;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.example.angluswang.mobilesafe.R;
import com.example.angluswang.mobilesafe.db.dao.AddressDao;

/**
 * 归属地查询界面
 */
public class AddressActivity extends Activity {

    private EditText etNumber;
    private TextView tv_result;

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

        etNumber = (EditText) findViewById(R.id.et_number);
        tv_result = (TextView) findViewById(R.id.tv_result);

        Button query = (Button) findViewById(R.id.btn_address_query);
        query.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //trim() 功能除去字符串开头和末尾的空格或其他字符。
                String number = etNumber.getText().toString().trim();
                if (!TextUtils.isEmpty(number)) {
                    String address = AddressDao.getAddress(number);
                    tv_result.setText(address);
                }
            }
        });
    }
}

@@ -121,25 +121,88 @@
 id.text.
-TextUtils
+Editable;%0Aimport android.text.TextUtils;%0Aimport android.text.TextWatcher
 ;%0Aimport
@@ -1365,16 +1365,572 @@
      %7D);
+%0A%0A        // %E7%9B%91%E5%90%AC%E7%94%B5%E8%AF%9D%E8%BE%93%E5%85%A5%E6%96%87%E6%9C%AC%E6%A1%86%0A        etNumber.addTextChangedListener(new TextWatcher() %7B%0A            @Override%0A            public void beforeTextChanged(CharSequence s, int start, int count, int after) %7B%0A            %7D%0A%0A            @Override%0A            public void onTextChanged(CharSequence s, int start, int before, int count) %7B%0A                String address = AddressDao.getAddress(s.toString());%0A                tv_result.setText(address);%0A            %7D%0A%0A            @Override%0A            public void afterTextChanged(Editable s) %7B%0A            %7D%0A        %7D);
 %0A    %7D%0A%7D

添加文本框监听器： 实现实时更新 归属地查询结果