Android Listview搜索未返回正确的对应活动(TextWatcher)

Android Listview搜索未返回正确的对应活动(TextWatcher),android,listview,search,filter,textwatcher,Android,Listview,Search,Filter,Textwatcher,我有一个列表视图,其中包含单击每个项目时开始的相应活动。它很好用。但是当我搜索“Pedro”并点击它时,不要启动正确的活动。它打开了第一个活动“Joao.class” 这是我的密码。请,我需要一个详细的解释。我不太懂Java,所以有人可以向我解释或者告诉我应该在哪里修改代码 非常感谢 public class Main extends Activity { private ListView lv1; private EditText ed; private String lv_arr[]

我有一个列表视图,其中包含单击每个项目时开始的相应活动。它很好用。但是当我搜索“Pedro”并点击它时,不要启动正确的活动。它打开了第一个活动“Joao.class”

这是我的密码。请,我需要一个详细的解释。我不太懂Java,所以有人可以向我解释或者告诉我应该在哪里修改代码

非常感谢

public class Main extends Activity {

   private ListView lv1;
private EditText ed;
private String lv_arr[]=  {"Android","Cupcake","Donut","Eclairs","AndroidPeople","Froyo",};
private ArrayList<String> arr_sort= new ArrayList<String>();
int textlength=0;
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
lv1=(ListView)findViewById(R.id.ListView01);
ed=(EditText)findViewById(R.id.EditText01);
lv1.setOnItemClickListener(new OnItemClickListener(){

public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {



       if ("João".equals(lv_arr[position])) {
           Intent myIntent = new Intent(Main.this, Joao.class);
           startActivity(myIntent);
       }

       if ("Maria".equals(lv_arr[position])) {
           Intent myIntent = new Intent(Main.this, Maria.class);
           startActivity(myIntent);
       }

       if ("Pedro".equals(lv_arr[position])) {
           Intent myIntent = new Intent(Main.this, Pedro.class);
           startActivity(myIntent);
       }


}

        });





// By using setAdpater method in listview we an add string array in list.
lv1.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 ,    lv_arr));
ed.addTextChangedListener(new TextWatcher() {

public void afterTextChanged(Editable s) {
}

public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}

public void onTextChanged(CharSequence s, int start, int before,
int count) {

textlength=ed.getText().length();
arr_sort.clear();
for(int i=0;i<lv_arr.length;i++)
{
if(textlength<=lv_arr[i].length())
{
if(ed.getText().toString().equalsIgnoreCase((String) lv_arr[i].subSequence(0,    textlength)))
{
arr_sort.add(lv_arr[i]);
}
}
}

lv1.setAdapter(new ArrayAdapter<String>(Main.this,android.R.layout.simple_list_item_1  , arr_sort));

}
});
}

} 
public类主扩展活动{
私有ListView lv1;
私人编辑文本;
私有字符串lv_arr[]={“Android”、“纸杯蛋糕”、“甜甜圈”、“Eclairs”、“AndroidPeople”、“Froyo”、};
private ArrayList arr_sort=new ArrayList();
int textlength=0;
@凌驾
创建公共空间(捆绑冰柱)
{
超级冰柱;
setContentView(R.layout.main);
lv1=(ListView)findViewById(R.id.ListView01);
ed=(EditText)findViewById(R.id.EditText01);
lv1.setOnItemClickListener(新的OnItemClickListener(){
公共单击(适配器视图arg0,视图arg1,内部位置,
长arg3){
如果(“João.”等于(lv_arr[位置]){
Intent myIntent=新Intent(Main.this,Joao.class);
星触觉(myIntent);
}
如果(“玛丽亚”。等于(lv_arr[位置]){
Intent myIntent=新Intent(Main.this,Maria.class);
星触觉(myIntent);
}
如果(“Pedro”。等于(lv_arr[位置]){
Intent myIntent=新Intent(Main.this,Pedro.class);
星触觉(myIntent);
}
}
});
//通过在listview中使用setAdPath方法,我们在列表中添加了一个字符串数组。
lv1.setAdapter(新的ArrayAdapter(这个,android.R.layout.simple_list_item_1,lv_arr));
ed.addTextChangedListener(新的TextWatcher(){
公共无效后文本已更改(可编辑){
}
更改前的公共无效(字符序列、整数开始、整数计数、,
整数后){
}
public void onTextChanged(字符序列,int start,int before,
整数计数){
textlength=ed.getText().length();
arr_sort.clear();

对于(int i=0;i我猜android.R.layout.simple_list_item_1中的数据在排序后与数组中的数据不匹配。您需要从arr_sort中获取值,而不是查看数组。例如:


if(“Pedro”.equals(arr_sort.get(position))){

所以,彼得,我现在搜索佩德罗的时候它能用了。但是,listview lv_arr不再起作用了。应用程序正在播放,当我点击一个特定的项目时它就关闭了:/你需要给我更多的特定信息来给你有用的信息。例如:你更新的onItemClick函数是什么。logcat输出是什么ut(来自eclipse调试器),当应用程序崩溃时输出。(您也可以从playstore下载一个名为catlog的程序,在手机上查看这些日志)