Reputation: 693
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 displayed in one TextView, 'No' should be displayed in another TextView, and 'Dontknow' should be displayed in another TextView, but how can I do this, can anyone give me some idea (I am new to Android).
Upvotes: 0
Views: 1419
Reputation: 234795
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.
Upvotes: 0
Reputation: 200080
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.
Upvotes: 2
Reputation: 1585
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
Upvotes: 1
Reputation: 581
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"
/>
Upvotes: 1