我无法从我的SearchableActivity
发送包含我的CompanyProfileActivity
的{{1}}。虽然我可以在ActionBar
中输入搜索查询,但当我点击搜索按钮时,它什么也没做。
我试图寻找类似的相同问题解决方案,但是没有给出的答案帮助我解决了我的问题。
这是我的代码段:
的AndroidManifest.xml:
CompanyProfileActivity
SearchableActivity.java:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".UserPrivateInfoSignUpActivity" />
<activity android:name=".CompanySignUpActivity" />
<activity android:name=".UserInterestsSignUpActivity" />
<activity android:name=".UserProfileActivity" />
<activity android:name=".CompanySignUpProductsActivity" />
<activity android:name=".CompanyProfileActivity" />
<meta-data
android:name="android.app.default_searchable"
android:value=".SearchableActivity" />
<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>
</application>
company_profile_action_bar.xml:
public class SearchableActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_searchable);
// Get the intent, verify the action and get the query
Intent intent = getIntent();
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
doMySearch(query);
}
}
private void doMySearch(String query) {
Toast.makeText(this, query, Toast.LENGTH_SHORT).show();
}
}
searchable.xml:
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/analyse_persona"
android:title="Analyse Persona" />
<item android:id="@+id/change_password"
android:title="Change Password" />
<item android:id="@+id/edit_info"
android:title="Edit Info" />
<item android:id="@+id/persona_history"
android:title="Persona List History" />
<item android:id="@+id/log_out"
android:title="Log Out" />
<item android:id="@+id/search_persona"
android:title="search"
android:icon="@drawable/baseline_search_white_24"
app:showAsAction = "ifRoom"
app:actionViewClass="android.widget.SearchView"
/>