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 6808965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:01:19+00:00 2026-05-26T20:01:19+00:00

I want to get text from file, and show it on TextView sorted. I

  • 0

I want to get text from file, and show it on TextView sorted.

I have class called RankActivity where I with zapisi() method writing one string and one integer called poenibrojanje to the file called 3.txt.

public void zapisi() {
    // WRITING
    String eol = System.getProperty("line.separator");
    String a = txtIme.getText().toString();
    try {
        FileOutputStream fOut = openFileOutput("3.txt", MODE_APPEND);

        OutputStreamWriter osw = new OutputStreamWriter(fOut);

        osw.write("Ime: " + a + "  Poeni: " + a1.poenibrojanje + eol);

        // Log.d("Writing", "This is writing log: " + a +
        // +a1.poenibrojanje);

        // osw.flush();
        osw.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

Also I have class where I read stuff from file, and show it in TextView. That class is called RankPrikazActivity and here is full code.

package com.test.brzoracunanje;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class RankPrikazActivity extends Activity implements OnClickListener {
TextView tvRank, tvRankPrikaz;
Button btnPovratak;



protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.rankprikaz);

    tvRank = (TextView)findViewById(R.id.tvRank);
    tvRankPrikaz = (TextView)findViewById(R.id.tvRankPrikaz);
    btnPovratak = (Button)findViewById(R.id.btnPovratak);
    btnPovratak.setOnClickListener(this);
    citaj();

}


@Override
public void onClick(View v) {

    Intent intent = new Intent(this,PocetnaActivity.class);
    startActivity(intent);


}

public void citaj() {
    // READING
    String eol = System.getProperty("line.separator");
    try {
        BufferedReader input = new BufferedReader(new InputStreamReader(
                openFileInput("3.txt")));
        String line;
        StringBuffer buffer = new StringBuffer();
        while ((line = input.readLine()) != null) {
            buffer.append(line + eol);
        }
        //Log.d("Reading log", "This is reading log:" + buffer);
        //System.out.println(buffer);
        tvRankPrikaz.setText(buffer.toString());

    } catch (Exception e) {
        e.printStackTrace();
    }

}

}

With method called citaj() method under this class, I read it from file and show it in TextView with this line:

   tvRankPrikaz.setText(buffer.toString());

Now I want to show it on this text box sorted by integer poenibrojanje from RankActivity class.

How to do it?

  • 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-05-26T20:01:20+00:00Added an answer on May 26, 2026 at 8:01 pm

    Try this instead:

    public void citaj() {
        // READING
        try {
            BufferedReader input = new BufferedReader(new InputStreamReader(
                    openFileInput("3.txt")));
            String line;
            TreeMap<Integer,String> sorted_map = new TreeMap<Integer,String>(new Comparator(){
              public int compare(Object o1, Object o2){
                Integer i1 = (Integer)o1;
                Integer i2 = (Integer)o2;
                return -(i1.compareTo(i2));
              }
              public boolean equals(Object o1){
                return this == o1;
              }
            });
            while ((line = input.readLine()) != null) {
              Pattern intsOnly = Pattern.compile("\\d+");
              Matcher makeMatch = intsOnly.matcher(line);
              makeMatch.find();
              Integer inputInt = Integer.valueOf(makeMatch.group());
              sorted_map.put(inputInt, line);
            }
            //Log.d("Reading log", "This is reading log:" + buffer);
            //System.out.println(buffer);
            String toOutput = "";
            for(Integer i: sorted_map.keySet()){
              toOutput += sorted_map.get(i) + "\n";
            }
            tvRankPrikaz.setText(toOutput);
    
        } catch (Exception e) {
            e.printStackTrace();
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write the text (which I get from AJAX) to a file,
I have text file from which I need to get data by line by
I want to get text from current active line (the line where the caret
I want to get some text from a PHP page into an Android application.
i want to get first n words from text stored in my database without
I want to check if a particular char I get from the text field
I want to download a file from server to a local host. i have
I have my code to display information from a text file already: $myFile =
Hi all.. I want to get some information from my database and show into
I want to get the text between the td tags of an html page..

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.