Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
446 views
in Technique[技术] by (71.8m points)

java - How to change the style of letters depending on the displayed letters in android

I would like to where there is A, B, C, D, E .... change the style letters on a bold and change the background. is a possibility because I was trying to (commented out lines), but always something is not working.

public View getView(int position, View convertView, ViewGroup parent) {

    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View gridView;

    if (convertView == null) {

        gridView = new View(context);

        // get layout from mobile.xml
        gridView = inflater.inflate(R.layout.mobile, null);

        int y = position / 11;
        int x = position % 11;

        //if(x<x+11 || x> plansza.length || y<0 || y> plansza[x].length);

        // set value into textview
        TextView textView = (TextView) gridView
                .findViewById(R.id.grid_item_label);

        textView.setText((x > 0 && y > 0) ? plansza[x-1][y-1].toString().substring(0,1): mobileValues[position]);

        // set image based on selected text
        ImageView imageView = (ImageView) gridView
                .findViewById(R.id.grid_item_image);

        String mobile = mobileValues[position];
        //Spannable spn = (Spannable) textView.getText();
        SpannableString spannable = new SpannableString(mobile);

        if (mobile.equals("A")) {
            //spannable.setSpan(new ForegroundColorSpan(Color.RED), 0, mobile.length(), 0);
            //spn.setSpan(new BackgroundColorSpan(Color.RED), 0, 7,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            //spn.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC),0, 7, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            //imageView.setImageResource(R.drawable.windows_logo);
        }
        else if (mobile.equals("B")) {
            //imageView.setImageResource(R.drawable.ios_logo);
        }
        else if (mobile.equals("C")) {
            //imageView.setImageResource(R.drawable.blackberry_logo);
        }
        else if (mobile.equals("D")) {
            //imageView.setImageResource(R.drawable.blackberry_logo);
        }
        else if (mobile.equals("E")) {
            //imageView.setImageResource(R.drawable.blackberry_logo);
        }
        else if (mobile.equals("F")) {
            //imageView.setImageResource(R.drawable.blackberry_logo);
        }
        else if (mobile.equals("G")) {
            //imageView.setImageResource(R.drawable.blackberry_logo);
        }
        else if (mobile.equals("H")) {
            //imageView.setImageResource(R.drawable.blackberry_logo);
        }
        else if (mobile.equals("I")) {
            //imageView.setImageResource(R.drawable.blackberry_logo);
        }
        else if (mobile.equals("J")) {
            //imageView.setImageResource(R.drawable.blackberry_logo);
        }else {
            //imageView.setImageResource(R.drawable.android_logo);
        }

    } else {
        gridView = (View) convertView;
    }

    return gridView;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Spannable wordtoSpan = new SpannableString("A");        

wordtoSpan.setSpan(new ForegroundColorSpan(Color.BLUE), 15, 30, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

textView.setText(wordtoSpan);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...