Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8311309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:46:15+00:00 2026-06-08T19:46:15+00:00

Hi can some one suggest me a sample example of how i can sort

  • 0

Hi can some one suggest me a sample example of how i can sort the textviews based on the numbers in textviews. I am able to get the text from the TextViews need to sort and place the lowest number first.

Thank you.

public void sortNumbers(View v) {

    String[] numbers = new String[7];
    numbers[0] = textView23.getText().toString();
    numbers[1] = textView33.getText().toString();
    numbers[2] = textView43.getText().toString();
    numbers[3] = textView53.getText().toString();
    numbers[4] = textView63.getText().toString();
    numbers[5] = textView73.getText().toString();
    numbers[6] = textView83.getText().toString();

    Integer[] intValues = new Integer[numbers.length];
    for (int i = 0; i < numbers.length; i++) {
        intValues[i] = Integer.parseInt(numbers[i].trim());
    }
    Collections.sort(Arrays.asList(intValues));

    for (int i = 0; i < intValues.length; i++) {
        Integer intValue = intValues[i];

        //here I want to assign sorted numberes to the TextViews


    }

}

So I have followed Jeffrey’s advice. Here is the code which still doesn’t work properly. What could be wrong?

Created an array of TextViews:

TextView[] tvs = new TextView[7];

    tvs[0] = textView23;
    tvs[1] = textView33;
    tvs[2] = textView43;
    tvs[3] = textView53;
    tvs[4] = textView63;
    tvs[5] = textView73;
    tvs[6] = textView83;

Sorted the array and assinged new values to the TextViews:

    Arrays.sort(tvs, new TVTextComparator());

    textView23.setText(tvs[0].getText().toString());
    textView33.setText(tvs[1].getText().toString());
    textView43.setText(tvs[2].getText().toString());
    textView53.setText(tvs[3].getText().toString());
    textView63.setText(tvs[4].getText().toString());
    textView73.setText(tvs[5].getText().toString());
    textView83.setText(tvs[6].getText().toString());    

And here is the Comporator class:

public class TVTextComparator implements Comparator<TextView> {
    public int compare(TextView lhs, TextView rhs) {

        Integer oneInt = Integer.parseInt(lhs.getText().toString());
        Integer twoInt = Integer.parseInt(rhs.getText().toString());

        return oneInt.compareTo(twoInt);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T19:46:18+00:00Added an answer on June 8, 2026 at 7:46 pm

    to sort your textViews, first put them in an array,

    TextView[] tvs = new TextView[7];
    tvs[0] = textView23;
    tvs[1] = textView33;
    // and so on
    

    note that if you have handle to the parent container, you could easily build the array by using ViewGroup.getChildCount() and getChildAt().

    now write a comparator for a text view,

    class TVTextComparator implements Comparator<TextView> {
      @Override
      public int compare(TextView lhs, TextView rhs) {
        return lhs.getText().toString().compareTo(rhs.getText().toString());
        // should check for nulls here, this is NOT a robust impl of compare()
      }
    }
    

    now use the comparator to sort the array,

    Arrays.sort(tvs, 0, tvs.length, new TVTextComparator());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My website's functionality would resemble with VWORKER.COM, ELANCE.COM, ODESK.COM etc. Can some one suggest
Can some please suggest an alternative to using two different handlers in the one
Can someone suggest me some JAVA string library for JAVA ME that includes basic
I am new to python programming..can someone suggest some way to do the following:
I'm new to wordpress. Can any one suggest me a best tutorial for learning
Can someone suggest a fast 2 way encryption algorithm for long ints? My candidates
Can someone suggest me how to implement a pop-up window in Java Swing. I
Can someone suggest me a way to map a template classes with a set
Can someone suggest what I am doing wrong? Basically I have a List Items,
Can someone suggest how I can place a logo image on the top of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.