android中的对象搜索,而不是listview的字符串列表
当我给出从对象到适配器的字符串列表时,它只搜索列表中的那些名称并显示它们(我需要搜索整个对象) 但它显示了一个单独的视图,比如下拉菜单,但我需要这样显示它们 当我键入一个字母时,它会获取所有单词并在下拉布局中显示它们,而不是像上图所示那样 为了在下拉列表中显示它们,我使用了以下代码android中的对象搜索,而不是listview的字符串列表,android,list,listview,search,autocomplete,Android,List,Listview,Search,Autocomplete,当我给出从对象到适配器的字符串列表时,它只搜索列表中的那些名称并显示它们(我需要搜索整个对象) 但它显示了一个单独的视图,比如下拉菜单,但我需要这样显示它们 当我键入一个字母时,它会获取所有单词并在下拉布局中显示它们,而不是像上图所示那样 为了在下拉列表中显示它们,我使用了以下代码 AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete_country); String[] ci
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete_country);
String[] cities= getResources().getStringArray(R.array.cities_array);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, cities);
textView.setAdapter(adapter);
AutoCompleteTextView textView=(AutoCompleteTextView)findViewById(R.id.autocomplete\u国家/地区);
字符串[]cities=getResources().getStringArray(R.array.cities\u数组);
ArrayAdapter=新的ArrayAdapter(这是android.R.layout.simple\u list\u item\u 1,城市);
setAdapter(适配器);
但是如何直接在listview中精简一个单词,如图所示
提前感谢如果您只想设置文本样式,您需要使用
SpannableString
我在一些应用程序中使用了一个util函数来设置文本的颜色,您可以通过将其更改为BackgroundColorSpan
如果您想使用带阴影的可绘制(圆形绿色)形状执行与图片中完全相同的操作,您可以使用DynamicDrawableSpan
请看这里:
我还需要对文本进行Highlite处理,但在此之前,如果我搜索一个单词,那么如何对其进行Highlite处理,并且为此我需要一个代码。在这里,我应该得到不止一个单词。啊,我明白了,您可能需要覆盖适配器,然后在
getView()中格式化它。
/**
* Taken with permission from PocketPermissions, this method is licensed under Apache 2.0
* Sets two colors in a single TextView or Button.
*/
public static void setTwoColorsTextStrings( String str1, String str2, TextView tv, Context c, int color1, int color2 )
{
SpannableString spnstr1 = new SpannableString( str1 );
SpannableString spnstr2 = new SpannableString( str2 );
int start = 0;
int len = str1.length();
int start2 = 0;
int len2 = str2.length();
spnstr1.setSpan( new ForegroundColorSpan( color1 ), start, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE );
spnstr2.setSpan( new ForegroundColorSpan( color2 ), start2, len2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE );
SpannableString fullString = SpannableString.valueOf( TextUtils.concat( spnstr1, spnstr2 ) );
tv.setText( fullString, BufferType.SPANNABLE );
}