How to inflate one layout to another layout with string search

百般思念 提交于 2020-04-11 04:05:12

问题


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

Thanks in advance...


回答1:


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


来源:https://stackoverflow.com/questions/12954411/how-to-inflate-one-layout-to-another-layout-with-string-search

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!