I want to show items on a SearchView
using SimpleCursorAdapter
. I have my code something like this:
mAdapter = new SimpleCursorAdapter(this,
R.layout.my_text_view,
null,
new String[]{"cityName"},
new int[] { android.R.id.text1},
CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
SearchManager searchManager = (SearchManager) getSystemService(this.SEARCH_SERVICE);
SearchView sv = (SearchView) findViewById(R.id.svBusqueda);
sv.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
sv.setSuggestionsAdapter(mAdapter);
sv.setIconifiedByDefault(false);
sv.setQueryHint("cityName");
And my text view layout used for the search items:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:scrollHorizontally="false"
android:singleLine="false"
android:maxLines="100"
android:gravity="center_vertical"
android:layout_weight="1"
android:minHeight="?android:attr/listPreferredItemHeightSmall" />
The search Works perfectly, but for some reason I can't make the text to wrap in the TextView
. ¿What am I missing?
You must use 2 parameters :
android:ellipsize="none" : the text is not cut on textview width
android:scrollHorizontally="false" the text wraps on as many lines as necessary
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.