I want to add a search widget and function to my app... The application includes a listview in a listfragment. I go through the android developer training and try to transfer the example code into my source code.. I add the searchview into my actionbar so far but without any functionality.. The next step in the android developer help is to create a searchable functionality, but I dont understand how to adapt that to my existing code.. I dont know where and how I can create a searchable Activity. My aim is to type any letter or word in my searchview and so, the listview get filtered. But I dont know what I have to do and especially where in my Code I have to add the example android developers code. please help..
This is my listfragment, where the listview should be filtered with the searchview..
import android.os.Bundle;
import android.widget.EditText;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class ListFragment extends Fragment {
ListFragmentData mData;
ListFragmentGUI mGUI;
ListFragmentApplicationLogic mAppLogic;
ListFragmentEventToListenerMapping mEventToListenerMapping;
EditText inputSearch;
public ListFragment () {
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View mView = inflater.inflate(R.layout.list_fragment, container, false);
initData();
initGUI(mView);
initApplicationLogic();
initEventToListenerMapping();
return mView;
}
private void initData() {
mData = new ListFragmentData(this);
}
private void initGUI(View mView) {
mGUI = new ListFragmentGUI(mView, mData);
}
private void initApplicationLogic() {
mAppLogic = new ListFragmentApplicationLogic(mData, mGUI);
}
private void initEventToListenerMapping() {
mEventToListenerMapping = new ListFragmentEventToListenerMapping(mGUI, mAppLogic);
}
}
This is my activity main:
import android.app.SearchManager;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.SearchView;
public class ActivityMain extends FragmentActivity {
private ActivityMainGUI mGUI;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initData();
initGUI();
initApplicationLogic();
initEventToListenerMapping();
getActionBar().setHomeButtonEnabled(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.options_menu, menu);
SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView =
(SearchView) menu.findItem(R.id.search).getActionView();
searchView.setSearchableInfo(
searchManager.getSearchableInfo(getComponentName()));
return true;
}
private void initData () {
}
public boolean onOptionsItemSelected(MenuItem item) { //Zurück Button
if (android.R.id.home == item.getItemId()){
finish();
}
return super.onOptionsItemSelected(item);
}
private void initGUI () {
setContentView(R.layout.activity_main);
mGUI = new ActivityMainGUI(this);
mGUI.getViewPager().setAdapter(new MyAdapter (getSupportFragmentManager()));
}
private void initApplicationLogic () {
}
private void initEventToListenerMapping () {
new ActivityMainEventToListenerMapping(mGUI);
}
}
... and my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://ift.tt/nIICcg"
package="de.fhdw.bfwi412a.geopfad"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="16" />
<permission
android:name="de.fhdw.bfwi412a.geopfad.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="de.fhdw.bfwi412a.geopfad.permission.MAPS_RECEIVE"/>
<!-- Permissions for Maps Integration -->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- My Location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!-- Maps Integration -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<!-- Google Play Services -->
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<!-- Google API Key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBvr424W8t4IhaSwcaG3vao2vMiNFsS_hI"/>
<activity
android:name=".ActivityMain"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
<activity
android:name=".ActivityLocations"
android:parentActivityName="de.fhdw.bfwi412a.geopfad.ActivityMain" >
</activity>
</application>
</manifest>
Please let me know if you need any other code to understand my problem or can give any help. Thak u guys!
No comments:
Post a Comment