如何使用 switch case 将搜索字符串中的 xml
字符串加粗。我想更改每个 xml 字符串 textview
并且此更改将在按钮单击时发生
String strfistsearch= mylist.get(7).get("data4");
if(strfistsearch.equals(strfistsearch))
{
mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View convertView1 = mInflater.inflate(R.layout.first_screen,viewFlow);
TextView txtf = (TextView)convertView1.findViewById(R.id.textView11);
String strfistsearch= mylist.get(7).get("data4");
Log.v("strfistsearch", strfistsearch);
SpannableStringBuilder sb = new SpannableStringBuilder(strfistsearch);
final StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD); // Span to make text sb.setSpan(bss, 0, 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE); // make first 4 characters Bold sb.setSpan(new ForegroundColorSpan(Color.RED), 0, 1, 0);
txtf.setText(sb);
}
else if(strfistsearch.equals(strfistsearch))
{
mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View convertView1 = mInflater.inflate(R.layout.second_screen,viewFlow);
TextView txtf = (TextView)convertView1.findViewById(R.id.textView11);
String strfistsearch= mylist.get(7).get("data4");
Log.v("strfistsearch", strfistsearch);
SpannableStringBuilder sb = new SpannableStringBuilder(strfistsearch); final StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD); // Span to make text sb.setSpan(bss, 0, 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE); // make first 4 characters Bold sb.setSpan(new ForegroundColorSpan(Color.RED), 0, 1, 0); txtf.setText(sb);
}
提前致谢...
最佳答案
您需要 XmlPullParser 对象来执行此操作
mLayoutInflator = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
xpp.setInput( new StringReader ( "xml string for layout" ) );
mLayoutInflator.inflate(xpp, (ViewGroup)root);
// root can be layout in which your inserting inflated view
关于android - 如何使用字符串搜索将一个布局扩展到另一个布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12954411/