Steps will be same like my previous post
just some will increase
For Autocomplete visit that post
http://androidprogrammingsolutions.blogspot.com/2015/02/autocomplete-using-json-and-mysql.html
Just Add a layout file named as:
search_layout
Paste following code into your xml file
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
style="?android:attr/dropDownItemStyle"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:background="#ffffff"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLargeInverse"
android:textColor="#000000" />
just some will increase
For Autocomplete visit that post
http://androidprogrammingsolutions.blogspot.com/2015/02/autocomplete-using-json-and-mysql.html
Just Add a layout file named as:
search_layout
Paste following code into your xml file
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
style="?android:attr/dropDownItemStyle"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:background="#ffffff"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLargeInverse"
android:textColor="#000000" />
And in Suggestion Adapter where your define layout define this layout file
Code for Your Suggestion Adapter
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.widget.ArrayAdapter;
import android.widget.Filter;
public class SuggestionAdapter extends ArrayAdapter<String> {
protected static final String TAG = "SuggestionAdapter";
private List<String> suggestions;
public SuggestionAdapter(Activity context, String nameFilter) {
//Here i changed Layout file
super(context, R.layout.search_layout);
suggestions = new ArrayList<String>();
}
@Override
public int getCount() {
return suggestions.size();
}
@Override
public String getItem(int index) {
return suggestions.get(index);
}
@Override
public Filter getFilter() {
Filter myFilter = new Filter() {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults filterResults = new FilterResults();
JsonParse jp = new JsonParse();
if (constraint != null) {
// A class that queries a web API, parses the data and
// returns an ArrayList<GoEuroGetSet>
List<SuggestGetSet> new_suggestions = jp
.getParseJsonWCF(constraint.toString());
suggestions.clear();
for (int i = 0; i < new_suggestions.size(); i++) {
suggestions.add(new_suggestions.get(i).getName());
}
// Now assign the values and count to the FilterResults
// object
filterResults.values = suggestions;
filterResults.count = suggestions.size();
}
return filterResults;
}
@Override
protected void publishResults(CharSequence contraint,
FilterResults results) {
if (results != null && results.count > 0) {
notifyDataSetChanged();
} else {
notifyDataSetInvalidated();
}
}
};
return myFilter;
}
}
No comments:
Post a Comment