Checked out the following:
How to have clicking the phone's search button do nothing?
But it does not work for me. Anybody has any other suggestions? Thank you.
Following Phil's suggestion updating the code according to his answer.
Shows the bug http://www.youtube.com/watch?v=9lekcH1JAf0&feature=youtu.be
So I have made a sample project. I have tested this on two different phones, Android version 2.3.5 and 4.1, I also tested this on emulator version 2.2. After I click the button show dialog, it shows the progress dialog just fine, and it should continue to do so. But clicking the Search button on the phones and the emulator makes the progress dialog disappear. Here's the class, and manifest follows.
Current behavior is that when the search button is clicked the progress dialog disappears.
Expected or needed behavior is to disable the search button, or similarly when the dialog is being shown and the search button is clicked, this click does not make the dialog disappear.
package com.example.test6;
import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
Button showDialogButton;
Context context;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showDialogButton = (Button) findViewById(R.id.showDialogButton);
showDialogButton.setOnClickListener(showDialog);
context = this;
startSearch(null, false, null, false);
}
private OnClickListener showDialog = new OnClickListener() {
@Override
public void onClick(View v) {
ProgressDialog progressDialog = new ProgressDialog(context);
progressDialog.show();
}
};
@Override
public boolean onSearchRequested() {
Log.d("onSearchRequested", "search key pressed");
return false;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test6"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="1"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="Test6" >
<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>
</manifest>
My searchable xml is at: res/xml/searchable.xml according to the reference provided. This is how my searchable.xml looks like:
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:searchSuggestAuthority="dictionary"
android:searchSuggestIntentAction="android.intent.action.VIEW"
android:includeInGlobalSearch="true">
</searchable>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…