最重要是 用TextWatcher 监听字母变化后 动态改变 listview
自带通讯录源码看不懂,希望哪位大神做过类似例子,麻烦讲解一下,最好附源码!!
------解决方案--------------------
addTextChangedListener 这个确实好一些,LZ的意思应该是实现这样的效果吧:
refresh_list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:id="@+id/txt_input"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ListView android:id="@+id/list1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
package com.joyband.android;
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
/**
* @author iampy
*
*/
public class RefreshListByEditText extends Activity implements
OnItemClickListener {
private static final String TAG = "====RefreshListByEditText_TAG====";
private EditText input;
private ListView listView;
private String[] listValue = { "Java", "JavaSE", "JavaEE", "Oracle 8",
"Oracle 9i", "Oracle 10g" };
private ArrayAdapter<String> adapter;
private Handler handler;
private static final int MSG_KEY = 0x1234;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.refresh_list);
input = (EditText) findViewById(R.id.txt_input);
input.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable editer) {
Log.d(TAG, "afterTextChanged");
}
public void beforeTextChanged(CharSequence value, int arg0,
int arg1, int arg2) {
Log.d(TAG, "beforeTextChanged");
}
public void onTextChanged(CharSequence value, int arg0, int arg1,
int arg2) {
Log.d(TAG, "onTextChanged");
Log.w(TAG, "input.text=" + value.toString());