2 znl 12 znl_12 于 2013.06.13 17:15 提问

autocomplete text view 不能运行的问题

当在程序的联系人列表中搜索联系人时,我想使用 autocompletetextview,但是成行执行不了。

Search.java:

public class Search extends  ListActivity {
  private static int[] TO = {R.id.name };
  private static String[] FROM = {DbConstants.NAME, DbConstants.PHONE, DbConstants.EMAIL,_ID};
  private Button sButton;
  private ListView lv1;
  private static SQLiteDatabase db;
  private DbCreate contacts;
  private Cursor cursor;
  private AutoCompleteTextView searchText;
protected SimpleCursorAdapter adapter;
protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.search);
    ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,new String[] {DbConstants.NAME});
    searchText=(AutoCompleteTextView)findViewById(R.id.searchtext);
    searchText.setAdapter(adapter);
    sButton=(Button)findViewById(R.id.searchButton);
    sButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // TODO Auto-generated method stub
            showDatabaseContent();
              lv1 = getListView();
              lv1.setTextFilterEnabled(true);
        }
    });
}

search.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">
      <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content">
       <AutoCompleteTextView
     android:id="@+id/searchtext"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_weight="1"
     android:hint="@string/searchDefault">
     <requestFocus />
         </AutoCompleteTextView> 
       <Button android:id="@+id/searchButton" 
      android:icon="@drawable/search" 
       android:text="Search"
      android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 
        </LinearLayout>
        <TextView
    android:id="@android:id/empty"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/empt" />
        <ListView
  android:id="@android:id/list"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content" />
    </LinearL ayout>

当我点击 search button 查找时会出错,其余时候都不出错。当我键入一个名称时也没有反应,问题出在哪里啊?

1个回答

u010434246
u010434246   2017.02.13 17:00

楼主:你自定义contentview ,还继承了listAcitivity ,导致覆盖了,执行search ,应该是会报错:空指针的

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!