0

我的應用程序結構如下: 主要活動 - 檢查它是第一次運行並打開註冊活動,否則打開默認活動。Android搜索查看片段沒有輸入?

默認活動 - 有一個導航抽屜和4個片段。

我有一個搜索視圖,在一個片段,而不是在工具欄,但在佈局。 甚至不顯示觸摸鍵盤! 我在做什麼錯?

layout.xml

<?xml version="1.0" encoding="utf-8"?> 
 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 
    xmlns:app ="http://schemas.android.com/apk/res-auto" 
 
    xmlns:tools="http://schemas.android.com/tools" 
 
    android:layout_width="match_parent" 
 
    android:layout_height="match_parent" 
 
    android:background="@color/list_background" 
 
    android:orientation="vertical"> 
 

 
    <!--<include layout="@layout/toolbar"/>--> 
 

 
    <LinearLayout 
 
     android:id="@+id/searchContent1" 
 
     android:layout_width="match_parent" 
 
     android:layout_height="wrap_content" 
 
     android:orientation="horizontal" 
 
     android:paddingBottom="20dp"> 
 

 
     <android.support.v7.widget.SearchView 
 
      android:layout_width="260dp" 
 
      android:layout_height="wrap_content" 
 
      android:id="@+id/ingredientSearch" 
 
      android:iconifiedByDefault="false" 
 
      android:inputType="text" 
 
      /> 
 

 
     
 

 
     <ImageButton 
 
      android:layout_width="50dp" 
 
      android:layout_height="wrap_content" 
 
      android:id="@+id/plateButton" 
 
      android:layout_gravity="right" 
 
      android:src="@drawable/ic_plate" 
 
      android:contentDescription="@string/container" /> 
 

 
    </LinearLayout> 
 

 
    <LinearLayout 
 
     android:id="@+id/searchContent2" 
 
     android:layout_width="match_parent" 
 
     android:layout_height="wrap_content" 
 
     android:orientation="vertical"></LinearLayout> 
 

 
</LinearLayout>

Searchable.xml

<?xml version="1.0" encoding="utf-8"?> 
 
<searchable xmlns:android="http://schemas.android.com/apk/res/android" 
 
    android:label="@string/app_name" 
 
    android:hint="Hint"> 
 

 
</searchable>

艙單

<?xml version="1.0" encoding="utf-8"?> 
 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
 
    package="com.smart_mat.dev.main" > 
 

 
    <application 
 
     android:allowBackup="true" 
 
     android:icon="@drawable/ic_launcher" 
 
     android:label="@string/app_name" 
 
     android:theme="@style/AppTheme" > 
 
     <activity 
 
      android:name="com.smart_mat.dev.main.MainActivity" 
 
      android:label="@string/title_activity_main" 
 
      android:theme="@android:style/Theme.NoDisplay"> 
 
      <intent-filter> 
 
       <action android:name="android.intent.action.MAIN" /> 
 
       <category android:name="android.intent.category.LAUNCHER" /> 
 
      </intent-filter> 
 
     </activity> 
 

 
     <activity android:name="com.smart_mat.dev.main.AlwaysActivity"> 
 
      <intent-filter> 
 
       <action android:name="android.intent.action.VIEW"/> 
 
      </intent-filter> 
 
      <intent-filter> 
 
       <action android:name="android.intent.action.SEARCH" /> 
 
      </intent-filter> 
 
      <meta-data android:name="android.app.default_searchable" 
 
       android:value=".SearchActivity"/> 
 
     </activity> 
 

 
     <activity android:name="com.smart_mat.dev.main.SearchActivity" > 
 
      <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.smart_mat.dev.userprofiledata.UserGoal"> 
 
      <intent-filter> 
 
       <action android:name="android.intent.action.VIEW"/> 
 
      </intent-filter> 
 
     </activity> 
 

 
         
 
     <activity android:name="com.smart_mat.dev.login.Login"> 
 
      <intent-filter> 
 
       <action android:name="android.intent.action.VIEW"/> 
 
      </intent-filter> 
 
     </activity> 
 

 
     <activity android:name="com.smart_mat.dev.login.SignUp"> 
 
      <intent-filter> 
 
       <action android:name="android.intent.action.VIEW"/> 
 
      </intent-filter> 
 
     </activity> 
 
    </application> 
 

 
</manifest>

+1

請教我如何在oncreateoptionmenu();中聲明searchview。 – 2015-02-24 11:06:56

+0

@SurenderKumar'searchView =(SearchView)dataSearch.findViewById(R.id.ingredientSearch);'但它在'onCreateView'因爲searchView不在actionBar中。 – Sndn 2015-02-25 13:59:40

+0

你可以發佈searchview代碼嗎? – 2015-02-25 18:02:18

回答

0

在片段搜索視圖應該這樣調用

搜索查看搜索查看=(搜索查看)getActivity()。findViewById(R.id.searchView1 );

searchView.setOnQueryTextListener(new OnQueryTextListener() { 

     @Override 
     public boolean onQueryTextSubmit(String query) { 
      Log.d("query", query); 
      return false; 
     } 

     @Override 
     public boolean onQueryTextChange(String newText) { 
      Log.d("genres 1", newText); 
      fillAdapter(newText); 
      return false; 
     } 
    });