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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:05:23+00:00 2026-06-08T15:05:23+00:00

Hi I am writting an android application to get information from a url and

  • 0

Hi I am writting an android application to get information from a url and show it in a ListView. All are working well. but it takes long time to show the View because i read the file from url on onCreate() method.

  1. I want read from the URL asynchronously, so view response time will not harmed.
  2. Am I using the ProgressBar correctly?.

    public class cseWatch extends Activity  {
        TextView txt1 ;
        Button btnBack;
        ListView listView1;
        /** Called when the activity is first created. */
        @Override
    
        public void onCreate(Bundle savedInstanceState) {
    
            super.onCreate(savedInstanceState);
            setContentView(R.layout.searchresult);
    
            Button btnBack=(Button) findViewById(R.id.btn_bck);
            btnBack.setOnClickListener(new View.OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Intent MyIntent1 = new Intent(v.getContext(),cseWatchMain.class);
                    startActivity(MyIntent1);
                }
            });
    
            ArrayList<SearchResults> searchResults = GetSearchResults();
    
            //after loaded result hide progress bar
            ProgressBar pb = (ProgressBar) findViewById(R.id.progressBar1);
            pb.setVisibility(View.INVISIBLE);
    
            final ListView lv = (ListView) findViewById(R.id.listView1);
            lv.setAdapter(new MyCustomBaseAdapter(cseWatch.this, searchResults));
    
            lv.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> a, View v, int position, long id) {
                    Object o = lv.getItemAtPosition(position);
                    SearchResults fullObject = (SearchResults)o;
                    Toast.makeText(cseWatch.this, "You have chosen: " + " " + fullObject.getName(), Toast.LENGTH_LONG).show();
                }
            });
    
    
        }//end of onCreate
    
    
    private ArrayList<SearchResults> GetSearchResults(){
        ArrayList<SearchResults> results = new ArrayList<SearchResults>();
    
        SearchResults sr;
        InputStream in;
        try{
            txt1 = (TextView) findViewById(R.id.txtDisplay);
            txt1.setText("Sending request...");
            DefaultHttpClient httpclient = new DefaultHttpClient();
            HttpGet httpget = new HttpGet("http://www.myurl?reportType=CSV");
            HttpResponse response = httpclient.execute(httpget);
            in = response.getEntity().getContent();
    
            txt1.setText("parsing CSV...");
    
    
            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
                try {
                    String line;
                    reader.readLine(); //IGNORE FIRST LINE
    
                    while ((line = reader.readLine()) != null) {
                         String[] RowData = line.split(",");
                         sr = new SearchResults();
    
                         String precent = String.format("%.2g%n",Double.parseDouble(RowData[12])).trim();
    
                         double chng=Double.parseDouble(RowData[11]);
                         String c;
                         if(chng > 0){
                             sr.setLine2Color(Color.GREEN);
                             c="▲";
                         }else if(chng < 0){
                             sr.setLine2Color(Color.rgb(255, 0, 14));
                             c="▼";
                         }else{
                             sr.setLine2Color(Color.rgb(2, 159, 223));
                             c="-";
                         }
    
                         sr.setName(c+RowData[2]+"-"+RowData[1]);
    
    
                         DecimalFormat fmt = new DecimalFormat("###,###,###,###.##");
                         String price = fmt.format(Double.parseDouble(RowData[6])).trim();
                         String tradevol = fmt.format(Double.parseDouble(RowData[8])).trim();
    
                         sr.setLine1("PRICE: Rs."+price+" TRADE VOL:"+tradevol);
                         sr.setLine2("CHANGE:"+c+RowData[11]+" ("+precent+"%)");
                         results.add(sr);
                         txt1.setText("Loaded...");
                        // do something with "data" and "value"
                    }
                }
                catch (IOException ex) {
                    Log.i("Error:IO",ex.getMessage());
                }
                finally {
                    try {
                        in.close();
                    }
                    catch (IOException e) {
                        Log.i("Error:Close",e.getMessage());
                    }
                }
        }catch(Exception e){
            Log.i("Error:",e.getMessage());
            new AlertDialog.Builder(cseWatch.this).setTitle("Watch out!").setMessage(e.getMessage()).setNeutralButton("Close", null).show();  
        }
    
        return results;
       }
    
    } 
    
  • 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-08T15:05:24+00:00Added an answer on June 8, 2026 at 3:05 pm

    AsyncTask should be used to move the heavylifting away from UI thread. http://developer.android.com/reference/android/os/AsyncTask.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writting a client(Android) - server(c#) application. I get the code from here: How
I'm writing an Android application, which uses AccountManager to get the token. From an
I'm writing my first Android application and trying to get my head around communication
I am writting an android application and i want to display a webpage inside
I'm writing an android application, and I would like to get an xml string
I am writing a simple application to get familiar with android programming. Today I
I'm writing an Android application and I've been seeing some odd behavior from Calendar
I am developing an Android application where I get the following exception while writing
I am writing an Android application which can enable and disable the Network Data
I am writing an Android application which uses several 3D models. Such a model

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.