如何通过字符串搜索将一个布局充气到另一种布局 [英] How to inflate one layout to another layout with string search
本文介绍了如何通过字符串搜索将一个布局充气到另一种布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从带有开关大小写的搜索字符串中将两个xml
字符串加粗,并且我想更改每个xml字符串textview
,并且此更改将在按钮上单击
How to bold both xml
string from search string with switch case.and i want to change each xml string textview
and this change will be on button click
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对象才能实现
You need XmlPullParser object to do this
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
这篇关于如何通过字符串搜索将一个布局充气到另一种布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文