0

如何在按钮单击时匹配页面指示器的不同布局上的字符串,例如 first.xml、second.xml 和 third.xml。我正在使用 convertview,但没有将每个布局 xml 的值加粗。

 mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  View convertView1 = mInflater.inflate(R.layout.first_screen,null);

// 这是converview

String strfistsearch=   mylist.get(9).get("data1");  
      Log.v("strfistsearch", strfistsearch);
    if(strfistsearch.equals(strfistsearch))
      {   
             mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              View   convertView1 = mInflater.inflate(R.layout.first_screen,null);        
               TextView txtf = (TextView)convertView1.findViewById(R.id.textView1);

     SpannableStringBuilder sb = new SpannableStringBuilder(strfistsearch);
    final StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD); // Span to make text 
    sb.setSpan(bss, 0, 2, Spannable.SPAN_INCLUSIVE_INCLUSIVE); // make first 4 characters Bold 
    sb.setSpan(iss, 4, 6, Spannable.SPAN_INCLUSIVE_INCLUSIVE); // make last 2 characters Italic
    sb.setSpan(new ForegroundColorSpan(Color.RED), 0, 2, 0);
    txtf.setText(sb);

       }
    else if(strfistsearch.equals(strfistsearch))
       {
               mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              View   convertView1 = mInflater.inflate(R.layout.first_screen,null);        
               TextView txtf = (TextView)convertView1.findViewById(R.id.textView1);  
     SpannableStringBuilder sb = new SpannableStringBuilder(strfistsearch);
    final StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD); // Span to make text 
    sb.setSpan(bss, 0, 2, Spannable.SPAN_INCLUSIVE_INCLUSIVE); // make first 4 characters Bold 
    sb.setSpan(iss, 4, 6, Spannable.SPAN_INCLUSIVE_INCLUSIVE); // make last 2 characters Italic
    sb.setSpan(new ForegroundColorSpan(Color.RED), 0, 2, 0);
    txtf.setText(sb);

    }

    else if(strfistsearch.equals(strfistsearch))
    {
             mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              View   convertView1 = mInflater.inflate(R.layout.first_screen,null);        
               TextView txtf = (TextView)convertView1.findViewById(R.id.textView1);  
     SpannableStringBuilder sb = new SpannableStringBuilder(strfistsearch);
    final StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD); // Span to make text 
    sb.setSpan(bss, 0, 2, Spannable.SPAN_INCLUSIVE_INCLUSIVE); // make first 4 characters Bold 
    sb.setSpan(iss, 4, 6, Spannable.SPAN_INCLUSIVE_INCLUSIVE); // make last 2 characters Italic
    sb.setSpan(new ForegroundColorSpan(Color.RED), 0, 2, 0);
    txtf.setText(sb);
    }

如何解决此问题..在此先感谢..

4

0 回答 0