Loading data to TextView in Android

前端 未结 5 1902
生来不讨喜
生来不讨喜 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:38

    Use setText() method of TextView to load text into it.

    0 讨论(0)
  • 2021-01-28 23:49

    If you want to split comma-separated strings, take a look at using java.util.StringTokenizer. You can tell it to use , as the token separator.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-01-29 00:00

    You can just declare 3 separate TextView in you Activity layout file. Using attribute android:text you can assign the text for the TextView.

    Example:

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Yes"
        />
    
    0 讨论(0)
  • 2021-01-29 00:03

    parse xml file store that in a string.take an array like String[] array = parsedstring.split(","); then take 3 text views ,put array[0],array[1],array[2] on to textview

    0 讨论(0)
提交回复
热议问题