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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:46:15+00:00 2026-05-30T10:46:15+00:00

I am a beginner. I need an item by clicking on the list to

  • 0

I am a beginner. I need an item by clicking on the list to send data “link” to activities “DownloadFile.java”. The activity “DownloadFile.java” I need to replace the data with “String fileURL =” data for the “link” with the previous activities. Thank you very much.

acivity1

public class Mangalist extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.listplaceholdermanga);

    ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();


    String xml = XMLmanga.getXML();
    Document doc = XMLmanga.XMLfromString(xml);

    int numResults = XMLmanga.numResults(doc);

    if((numResults <= 0)){
        Toast.makeText(Mangalist.this, "Geen resultaten gevonden", Toast.LENGTH_LONG).show();  
        finish();
    }

    NodeList nodes = doc.getElementsByTagName("result");

    for (int i = 0; i < nodes.getLength(); i++) {                           
        HashMap<String, String> map = new HashMap<String, String>();    

        Element e = (Element)nodes.item(i);
        map.put("id", XMLmanga.getValue(e, "id"));
        map.put("name", "Kapitola:" + XMLmanga.getValue(e, "name"));
        map.put("volume", "Volume: " + XMLmanga.getValue(e, "volume"));
        map.put("link", XMLmanga.getValue(e, "link"));
        mylist.add(map);            
    }       

    ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.mangalist, 
                    new String[] { "name", "volume" }, 
                    new int[] { R.id.item_title, R.id.item_subtitle });

    setListAdapter(adapter);

    final ListView lv = getListView();
    lv.setTextFilterEnabled(true);  
    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {              
            @SuppressWarnings("unchecked")
            HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);                   
            Toast.makeText(Mangalist.this, "Kapitola '" + o.get("id") + "'", Toast.LENGTH_LONG).show(); 
            Intent i = new Intent(Mangalist.this,DownloadFile.class);
            startActivity(i);

        }
    });
}

DownloadFile activity

public class DownloadFile extends Activity {
public static final String LOG_TAG = "Android Downloader";

//initialize our progress dialog/bar
private ProgressDialog mProgressDialog;
public static final int DIALOG_DOWNLOAD_PROGRESS = 0;

//initialize root directory
File rootDir = Environment.getExternalStorageDirectory();

//defining file name and url
public String fileName = "xx.jpg";
public String fileURL = "https://xx.JPG";

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    //setting some display
    setContentView(R.layout.main);
    TextView tv = new TextView(this);
    tv.setText("Android Download File With Progress Bar");

    //making sure the download directory exists
    checkAndCreateDirectory("/my_downloads");

    //executing the asynctask
    new DownloadFileAsync().execute(fileURL);
}

//this is our download file asynctask
class DownloadFileAsync extends AsyncTask<String, String, String> {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        showDialog(DIALOG_DOWNLOAD_PROGRESS);
    }


    @Override
    protected String doInBackground(String... aurl) {

        try {
            //connecting to url
            URL u = new URL(fileURL);
            HttpURLConnection c = (HttpURLConnection) u.openConnection();
            c.setRequestMethod("GET");
            c.setDoOutput(true);
            c.connect();

            //lenghtOfFile is used for calculating download progress
            int lenghtOfFile = c.getContentLength();

            //this is where the file will be seen after the download
            FileOutputStream f = new FileOutputStream(new File(rootDir + "/my_downloads/", fileName));
            //file input is from the url
            InputStream in = c.getInputStream();

            //here's the download code
            byte[] buffer = new byte[1024];
            int len1 = 0;
            long total = 0;

            while ((len1 = in.read(buffer)) > 0) {
                total += len1; //total = total + len1
                publishProgress("" + (int)((total*100)/lenghtOfFile));
                f.write(buffer, 0, len1);
            }
            f.close();

        } catch (Exception e) {
            Log.d(LOG_TAG, e.getMessage());
        }

        return null;
    }

    protected void onProgressUpdate(String... progress) {
         Log.d(LOG_TAG,progress[0]);
         mProgressDialog.setProgress(Integer.parseInt(progress[0]));
    }

    @Override
    protected void onPostExecute(String unused) {
        //dismiss the dialog after the file was downloaded
        dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
    }
}

//function to verify if directory exists
public void checkAndCreateDirectory(String dirName){
    File new_dir = new File( rootDir + dirName );
    if( !new_dir.exists() ){
        new_dir.mkdirs();
    }
}

//our progress bar settings
@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
        case DIALOG_DOWNLOAD_PROGRESS: //we set this to 0
            mProgressDialog = new ProgressDialog(this);
            mProgressDialog.setMessage("Downloading file...");
            mProgressDialog.setIndeterminate(false);
            mProgressDialog.setMax(100);
            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            mProgressDialog.setCancelable(true);
            mProgressDialog.show();
            return mProgressDialog;
        default:
            return null;
    }
}
  • 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-30T10:46:16+00:00Added an answer on May 30, 2026 at 10:46 am

    The correct approach is to pass the data in the Intent that you use to launch the DownloadFile activity. In OnItemClickListener

    Intent i = new Intent(Mangalist.this,DownloadFile.class);
    i.putExtra("link", link /* link from your list item*/ );
    startActivity(i); //or startActivityForResult() if you want to come back to this activity
    

    and in your DownloadFile activity onCreate()

    Intent intent = getintent()
    String link = intent.getStringExtra("link");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a beginner in C++. I need to store list of addresses that
I am beginner in C++, I need to know which data structure to store
I am a .net beginner. I need to add some data to xml file
I am a Qt beginner and need to write some data classes. Would it
JS beginner here. I need help with a script to place different content in
Note: Near complete beginner to logic programming I need to compare two lists of
I am a beginner concerning development in C# and I need your advice to
I maybe need to do a project in Delphi and are a beginner in
I'm a beginner in ruby and in programming as well and need help with
i'm a beginner to php. i need to use php function which process some

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.