1

i am new to android developing and in some trouble and really need help.. Please read before posting suggested links.. i am developing a demo app which shows the installed application including system apps. Although i have done most of the work but i cannot get the ActionBar Search option to work.. Basically i want to search/filter the list of apps installed like the images as shown in this example --> Link : http://www.androidhub4you.com/2014/04/android-action-bar-search-inside.html

i saw many examples through stackoverflow such as using searchview,edititext in action bar, using filter and at developer.android website by creating a different searchable xml and activity file to implement search but just got confused implementing it in my activity code. Which is the real problem - Implementing the example code logic in my code

Code

I used a Listview in main activity_main.xml file shown below

activity_main.xml----

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:animateLayoutChanges="true">

<ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:divider="#848484"
    android:dividerHeight="1dp"
    android:animateLayoutChanges="true"
    android:listSelector="@drawable/listview_selector"
    android:textFilterEnabled="true"
    />

do i need to change this - >>>android:id="@android:id/list" -- to -- android:id="@+id/list" to use in the activity file ?

Menu.xml

<item android:id="@+id/menu_Action_Search"
      android:icon="@drawable/ic_action_search"
      android:title="@string/action_search"
      android:showAsAction="collapseActionView|always"
      android:actionViewClass="android.widget.SearchView"
      />

   <item
    android:id="@+id/menu_Sort_By_Size"
    android:orderInCategory="100"
    android:icon="@drawable/ic_action_sort_by_size"
    android:showAsAction="always|withText"
    android:title="@string/action_about"/>

TWO Activity Files First ** main activity for installed apps--** I used List for listing apps used ApplicationAdaptor as the adapter and package manager

private PackageManager packageManager = null;
private List<ApplicationInfo> applist = null;
private ApplicationAdapter listadaptor = null;

This is OnCreate()...Below

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

    packageManager = getPackageManager();

    new LoadApplications().execute();

}

Implemented the onListItemClick and LoadApplication extending AsyncTask

Second Activity File

Which is the adapter activity..Part of its code.

public class ApplicationAdapter extends ArrayAdapter<ApplicationInfo> {
private List<ApplicationInfo> appsList = null;
private Context context;
private PackageManager packageManager;
//private int isChecked;

public ApplicationAdapter(Context context, int textViewResourceId,
        List<ApplicationInfo> appsList) {
    super(context, textViewResourceId, appsList);
    this.context = context;
    this.appsList = appsList;
    packageManager = context.getPackageManager();
}

Searchable Method at developer.android website

Searchable.xml

<searchable xmlns:android="http://schemas.android.com/apk/res/android" 
android:label="@string/app_name"
android:hint="@string/search_hint" 
>

SearchableActivity

public class SearchableActivity extends ListActivity{

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.xml.searchable);

    handleIntent(getIntent());

}

@Override
protected void onNewIntent(Intent intent) {

    handleIntent(intent);
}


private void handleIntent(Intent intent) {

    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        //use the query to search your data somehow
        doMySearch(query);

    }
}


private void doMySearch(String queryString){
    /*ListView appList = (ListView)findViewById(android.R.id.list);
    appList.setAdapter(null);
    //ArrayAdapter<ApplicationInfo> listadaptor = new ArrayAdapter(getApplicationContext(),R.layout.snippet_list_row, appList);

    ApplicationAdapter listadaptor = new ApplicationAdapter(getApplicationContext(), R.layout.snippet_list_row, appsList)*/


}   

}

AndroidManifest.xm

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.listapps"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="19" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name">
    <activity
        android:name="com.example.listapps.AllApps"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

</application>

I need some help to search/filter the ListView of List .. Please help coz i am stuck with this confusion from few days now.

Since this is my first question in Stackoverflow community I tried to explain my problem with as much detail as possible so please go easy on me. Any Points or instructions will be really helpful.

Thanks

  • refer this link, it could help you: http://stackoverflow.com/questions/21585326/implementing-searchview-in-action-bar – VINIL SATRASALA Sep 12 '14 at 08:32
  • @VINILSATRASALA thanks for the link its surely helpful. Instead of List items wherever present in the example i will use the List items ? Right..?? – SharingIsCaring Sep 13 '14 at 08:37

0 Answers0