Reputation: 19378
I'm trying to implement a local search in my activity. I've added an appropriate intent filter and metadata tag to manifest file but if I click Search button it invokes standard android search box. What's my problem?
Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nixsolutions.invertigation.android.dataprovider"
android:versionCode="1"
android:versionName="1.0">
<application
android:icon="@drawable/icon"
android:label="@string/app_name"
android:debuggable="true">
<provider
android:name="NoteProvider"
android:authorities="com.nixsolutions.investigation.android.NoteProvider">
</provider>
<activity
android:name="NotesList">
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action
android:name="android.intent.action.SEARCH" />
<category
android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
</application>
<uses-sdk
android:minSdkVersion="7" />
</manifest>
searchable.xml:
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="Custom search"
android:hint="Custom hint"
android:searchMode="showSearchLabelAsBadge"
/>
Upvotes: 2
Views: 2697
Reputation: 335
private List<MyBillResponseItem> itemList;
private List<MyBillResponseItem> mainitemList;
private List<MyBillResponseItem> selecteditemList;
itemList = new ArrayList<MyBillResponseItem>();
selecteditemList = new ArrayList<MyBillResponseItem>();
mainitemList = new ArrayList<MyBillResponseItem>();
void filter(String text) {
itemList.clear();
Log.d("tag ::", "mainitemList 02" + mainitemList.size());
for (MyBillResponseItem d : mainitemList) {
if (d.getTitle().toLowerCase().contains(text.toLowerCase())) {
itemList.add(d);
}
Log.d("tag ::", "itemList 02" + itemList.size());
}
//update recyclerview
myBillingAdapter.notifyDataSetChanged();
}
private void GetBillingList(Date newFromDate, Date newToDate) {
itemList.clear();
final AlertDialog dialog = Utils.dialogProgress(getActivity());
dialog.show();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
GetMyBillingReqEnvelope requestEnvelope = new GetMyBillingReqEnvelope();
final String deviceId = Settings.Secure.getString(getActivity().getContentResolver(), Settings.Secure.ANDROID_ID);
Log.d("tag ::", "device id :" + deviceId);
Date c = Calendar.getInstance().getTime();
System.out.println("Current time => " + c);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String formattedDate = df.format(c);
System.out.println(formattedDate);
Date date = null;
try {
date = df.parse(formattedDate);
System.out.println(date);
} catch (ParseException e) {
e.printStackTrace();
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String newFromDate1 = sdf.format(newFromDate);
String newToDate1 = sdf.format(newToDate);
RequestHeader requestHeader = new RequestHeader(Helper.getStringValue(getActivity(), "mobile"),
Helper.getStringValue(getActivity(), "password"), Helper.getStringValue(getActivity(), "fcmToken"),
Helper.getStringValue(getActivity(), "deviceId"), newFromDate1, newToDate1, empid);
GetMyBillingReqBody requestBody = new GetMyBillingReqBody();
requestEnvelope.setHeader(requestHeader);
requestEnvelope.setZbody(requestBody);
Call<GetMyBillingResEnvelope> responseEnvelopeCall = BhanuSamajApiImpl.getApi().getMyBilling(requestEnvelope);
responseEnvelopeCall.enqueue(new Callback<GetMyBillingResEnvelope>() {
@Override
public void onResponse(Call<GetMyBillingResEnvelope> call, Response<GetMyBillingResEnvelope> response) {
dialog.dismiss();
if (response != null) {
try {
GetMyBillingData data = ((GetMyBillingResEnvelope) response.body()).getBody().getGetMyBillsResponse();
ObjectMapper mapper = new ObjectMapper();
GetMyBillingResponse getMyBillingResponse = new GetMyBillingResponse();
getMyBillingResponse = mapper.readValue(data.getGetMyBillsResult().toString(), GetMyBillingResponse.class);
itemList.addAll(getMyBillingResponse.getMyBillResponse());
mainitemList.addAll(getMyBillingResponse.getMyBillResponse());
myBillingAdapter = new MyBillingAdapter(getActivity(), R.layout.adpt_billing, itemList);
recyclerView.setAdapter(myBillingAdapter);
selected();
if (dialog1.isShowing()) {
dialog1.dismiss();
}
// Log.d("tag", "CODE ::; " + myProfileResponse.getEmployeeAuth().getCode());
Log.d("tag", "response :: " + data.getGetMyBillsResult().toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
@Override
public void onFailure(Call<GetMyBillingResEnvelope> call, Throwable t) {
dialog.dismiss();
t.printStackTrace();
}
});
}
void selected() {
edtSearch.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
String text = edtSearch.getText().toString().toLowerCase(Locale.getDefault());
filter(text);
}
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
});
}
Upvotes: 0
Reputation: 1007099
I think you also need an activity flagged (on application level) as the one that is offering the search, via:
<meta-data android:name="android.app.default_searchable" android:value=".LoremSearch" />
(substituting in the proper value for android:value
)
E.g.:
<application android:icon="@drawable/icon" android:label="@string/app_name"
android:debuggable="true" android:allowBackup="true"
>
<meta-data android:name="android.app.default_searchable"
android:value=".MySearchActivity" />
<activity android:name=".MySearchActivity">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable"/>
</activity>
The way you have specified for an activity only, only enables search within that activity. Only adding the meta-data tag at application level enables search for all activities.
See here for a complete search project.
Upvotes: 2