Loading data to TextView in Android

前端 未结 5 1903
生来不讨喜
生来不讨喜 2021-01-28 23:22

I have a XML tag like \"Yes,No,Dontknow \" and I am parsing the XML file and getting the data. Now I need to display each option in separate TextView, i.e: \'yes\' should be dis

5条回答
  •  盖世英雄少女心
    2021-01-28 23:58

    You can use string tokenizer:

    StringTokenizer tokens = new StringTokenizer(theString, ",");
    while( tokens.hasMoreTokens() ){
        String token = tokens.nextToken();
        // here you must have the reference to the text view...
        textView.setText(token);
    }
    

    If you are creating the text views programmatically, then you must create or reference those text views inside the loop. Other wise, if the text views are static, you better put each token inside an array or something (words[0] will be Yes, word[1] will be No, etc) and then you set those strings manually.

提交回复
热议问题