方法setTextFilterEnabled(true)给出错误的结果。在输入..我不知道是什么问题。(它给出了错误的搜索结果)。
以下是我的演示应用程序的完整代码
public class AndroidCustomListActivity extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setListAdapter(new MyAdapter(this,android.R.layout.simple_list_item_1,R.id.textView1,getResources().getStringArray(R.array.names)));
getListView().setTextFilterEnabled(true);
}
private class MyAdapter extends ArrayAdapter<String>
{
public MyAdapter(Context context, int resource, int textViewResourceId,
String[] strings) {
super(context, resource, textViewResourceId, strings);
// TODO Auto-generated constructor stub
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater=(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row=inflater.inflate(R.layout.list_items, parent, false);
String[] items=getResources().getStringArray(R.array.names);
String[] items1=getResources().getStringArray(R.array.address);
ImageView iv=(ImageView) row.findViewById(R.id.imageView1);
TextView tv=(TextView) row.findViewById(R.id.textView1);
TextView tv1=(TextView) row.findViewById(R.id.textView2);
tv.setText(items[position]);
if(items[position].equals("Tuhin Bhatt"))
{
iv.setImageResource(R.drawable.tuhin);
tv1.setText(items1[position]);
}
else if(items[position].equals("Rikhil Jain"))
{
iv.setImageResource(R.drawable.ronaldo);
tv1.setText(items1[position]);
}
else if(items[position].equals("David Beckham"))
{
iv.setImageResource(R.drawable.davidbeckham);
tv1.setText(items1[position]);
}
else if(items[position].equals("Luis Figo"))
{
iv.setImageResource(R.drawable.luisfigo);
tv1.setText(items1[position]);
}
else if(items[position].equals("David Silva"))
{
iv.setImageResource(R.drawable.davidsilva);
tv1.setText(items1[position]);
}
else if(items[position].equals("Wayne Rooney"))
{
iv.setImageResource(R.drawable.waynerooney);
tv1.setText(items1[position]);
}
else if(items[position].equals("Iker Casillas"))
{
iv.setImageResource(R.drawable.ikercasillas);
tv1.setText(items1[position]);
}
return row;
}
}
}
其他一切正常。代码运行完全除了这个问题.... 我知道我发布了一个很长的代码..但我认为这可能有助于查明问题