Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android SearchView没有';不行。我不知道';我不知道是数据库还是别的什么?_Android_Database_Searchview_Android Actionbar Compat - Fatal编程技术网

Android SearchView没有';不行。我不知道';我不知道是数据库还是别的什么?

Android SearchView没有';不行。我不知道';我不知道是数据库还是别的什么?,android,database,searchview,android-actionbar-compat,Android,Database,Searchview,Android Actionbar Compat,我正在开发一个应用程序,我的searchview有问题,我看不到数据库的结果,下面是代码 MainActivity.Java public class SearchableActivity extends ListActivity{ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.s

我正在开发一个应用程序,我的searchview有问题,我看不到数据库的结果,下面是代码

MainActivity.Java

    public class SearchableActivity extends ListActivity{
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.search);
}
DatabaseTable db = new DatabaseTable(this);



private void handleIntent(Intent intent) {

    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        Cursor c = db.getWordMatches(query, null);
        //process Cursor and display results
    }
}
公共类MainActivity扩展ActionBarActivity实现OnClickListener{

ActionBar actionBar;
Button a;
Button b;
Button c;
Button d;
Button e;

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

    actionBar = getSupportActionBar();
    actionBar.setTitle("Trial");

    initialiseOnClick();
    a.setOnClickListener(this);
    b.setOnClickListener(this);
    c.setOnClickListener(this);
    d.setOnClickListener(this);
    e.setOnClickListener(this);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);

     SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    // Configure the search info and add any event listeners
     searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
     searchView.setIconifiedByDefault(true); // Do not iconify the widget; expand it by default
    return super.onCreateOptionsMenu(menu);



}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.action_search:
            onSearchRequested();
            return true;
        default:
            return false;
    }
}



private void initialiseOnClick() {
    // TODO Auto-generated method stub
    a = (Button) findViewById (R.id.button_a);
    b = (Button) findViewById (R.id.button_b);
    c = (Button) findViewById (R.id.button_c);
    d = (Button) findViewById (R.id.button_d);
    e = (Button) findViewById (R.id.button_e);
}



@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch(v.getId()){

    case R.id.button_a:
        Intent a = new Intent(MainActivity.this, EuropeActivity.class);
        startActivity(a);
    break;

    case R.id.button_b:
        Intent b = new Intent(MainActivity.this, AmericasActivity.class);
        startActivity(b);
    break;

    case R.id.button_c:
        Intent c = new Intent(MainActivity.this, AsiaActivity.class);
        startActivity(c);
    break;

    case R.id.button_d:
        Intent d = new Intent(MainActivity.this, OceaniaActivity.class);
        startActivity(d);
    break;

    case R.id.button_e:
        Intent e = new Intent(MainActivity.this, AfricaActivity.class);
        startActivity(e);
    break;

    }
}
}

activity_main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:background="#000000"
        android:layout_height="fill_parent">

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#000000"
                android:orientation="vertical" >

                <Button
                     android:id="@+id/button_a"
                    style="@style/ButtonMain"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/blue_button"
                    android:text="@string/europe" />


                <Button
                     android:id="@+id/button_b"
                    style="@style/ButtonMain"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/red_button"
                    android:text="@string/americas" />


                <Button
                     android:id="@+id/button_c"
                    style="@style/ButtonMain"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/yellow_button"
                    android:text="@string/asia" />

                <Button
                     android:id="@+id/button_d"
                    style="@style/ButtonMain"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/green_button"
                    android:text="@string/oceania" />


                <Button
                     android:id="@+id/button_e"
                    style="@style/ButtonMain"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/black_button"
                    android:text="@string/africa" />

            </LinearLayout>
    </ScrollView>
}

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">

    <ListView
            android:id="@+id/list"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />
</LinearLayout>
Manifest.xml

    <activity android:name=".SearchableActivity" >
        <intent-filter>
            <action android:name="android.intent.action.SEARCH" />
        </intent-filter>
        <meta-data android:name="android.app.searchable"
               android:resource="@xml/searchable"/>
    </activity>

    <activity
        android:name="com.example.trial.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <meta-data android:name="android.app.default_searchable" android:value=".SearchableActivity" />
    </activity>

问题是我可以看到actionbar,我可以在搜索对话框中编写,但是我看不到结果。我知道有点不对劲,但我不知道在哪里或什么地方

searchView.setOnQueryTextListener(new OnQueryTextListener() {

      @Override
        public boolean onQueryTextSubmit(String key) {
          //After you press Search/Enter control comes here with entered text in "key"
          return true;
        }

      @Override
      public boolean onQueryTextChange(String key) {
      //Each time you enter/modify a charcter, control comes here with entered text in "key"
      return true;
      }
});
    <activity android:name=".SearchableActivity" >
        <intent-filter>
            <action android:name="android.intent.action.SEARCH" />
        </intent-filter>
        <meta-data android:name="android.app.searchable"
               android:resource="@xml/searchable"/>
    </activity>

    <activity
        android:name="com.example.trial.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <meta-data android:name="android.app.default_searchable" android:value=".SearchableActivity" />
    </activity>
searchView.setOnQueryTextListener(new OnQueryTextListener() {

      @Override
        public boolean onQueryTextSubmit(String key) {
          //After you press Search/Enter control comes here with entered text in "key"
          return true;
        }

      @Override
      public boolean onQueryTextChange(String key) {
      //Each time you enter/modify a charcter, control comes here with entered text in "key"
      return true;
      }
});