Textview没有在列表中包装文本

时间:2015-10-20 13:19:09

标签: android textview

我想使用SearchViewSimpleCursorAdapter上展示商品。我的代码是这样的:

    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");

我的文字视图布局用于搜索项目:

<?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" />

搜索工作完美,但由于某种原因,我无法将文本包装在TextView中。我错过了什么?

1 个答案:

答案 0 :(得分:1)

您必须使用2个参数:

android:ellipsize="none" : the text is not cut on textview width

android:scrollHorizontally="false" the text wraps on as many lines as necessary