how to make thumbnail image with initials two char from name android?

前端 未结 4 617
粉色の甜心
粉色の甜心 2021-01-06 04:14

I want to thumbnail initials with two word for my image view like \"Peter Parker\" but am able to get only one word \"P\"while running code how can get second word after spa

4条回答
  •  伪装坚强ぢ
    2021-01-06 05:11

    it look's like your using substring to only grab the letters from position 0 to position 1, This is P in Petter

    holder.imgName?.text=teamData[position].userImage  
    

    .substring(0,1)

    If you'd like to grab the words Petter Parker, you have a few options.
    • IndexOf & Substring - find the position of a string and get the subtext after.
    • Substring - Subtext of string based on parameters

    If you plan to change the text length at any stage, you'll need to find the start of the word ( int start = yourString.indexOf("Petter"));
    and end of the word ( int end = yourString.indexOf(" "))

    IndexOf will return the position of the first letter in your query - Your case it's P in Petter --- So start+"petter".length()

    Here's an example of a barcode price checker app I'm working on

                        // STRING  FORMAT 00000899999:0.99   
    
                        String currentLine = "00000899999:0.99";
                        int breakPoint = currentLine.indexOf(":");
                        int end = currentLine.length();
                        int start = breakPoint + 1;
                        String Price = currentLine.substring(start,end);
    

    Price will be starting after (:) With +1 or include (:) with no + 1 and end at the lines length.

提交回复
热议问题