1

hi i made a program that counts the elements in an array and i done it already. Now i want to display the result in a textView.. I want to display it this way...

1 appeared 2times
2 appeared 1times
3 appeared 1times
6 appeared 1times

this is my code..

The last element only displays in the textView..
please help me..Thanks

 String []values = ( input.getText().toString().split(","));
 Arrays.sort(values);
 int c=1,i=0,range=4;
 while(i<values.length-1){
     while(values[i]==values[i+1]){
         c++; 
         i++;   
     }   
     jLabel7.setText(values[i] + " appeared " + c + " times");            
     c=1;
     i++;
     if(i==values.length-1)
         jLabel7.setText(values[i] + " appeared " + c + " times");
 } 
1
  • 1
    append all the values into a single String object and then use the setText method to display the string... Commented Sep 26, 2013 at 16:17

2 Answers 2

1

Try this:

jLabel7.setText(jLabel7.getText() + "\n" + values[i] + " appeared " + c + " times");

Att: If u are using swing componentes, is not a TextView but JLabel, or u are working for Android?

update your code to:

 String []values = ( input.getText().toString().split(","));
 Arrays.sort(values);
 int c=1,i=0,range=4;
 while(i<values.length-1){
     while(values[i]==values[i+1]){
         c++; 
         i++;   
     }   
     jLabel7.setText(jLabel7.getText() + "\n" + values[i] + " appeared " + c + " times");          
     c=1;
     i++;
     if(i==values.length-1)
         jLabel7.setText(jLabel7.getText() + "\n" + values[i] + " appeared " + c + " times");
 }
Sign up to request clarification or add additional context in comments.

1 Comment

se my increment on the answer
0

append all the values into a single String object and then use the setText method to display the string

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.