Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 需要有关android中listitem单击的帮助吗_Java_Android_Android Layout_Android Intent_Android Listview - Fatal编程技术网

Java 需要有关android中listitem单击的帮助吗

Java 需要有关android中listitem单击的帮助吗,java,android,android-layout,android-intent,android-listview,Java,Android,Android Layout,Android Intent,Android Listview,嗨,我已经创建了下载过程活动,它在点击按钮时运行。此活动在单击listitem时打开。但是现在我想在lisitem click上运行下载过程,而不是在button click上运行 ZipDownloader.java import java.io.File; import android.app.Activity; import android.app.ProgressDialog; import android.os.AsyncTask; import android.os.Bundle;

嗨,我已经创建了下载过程活动,它在点击按钮时运行。此活动在单击listitem时打开。但是现在我想在lisitem click上运行下载过程,而不是在button click上运行

ZipDownloader.java

import java.io.File;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Toast;

import com.kabelash.sg.util.DecompressZip;
import com.kabelash.sg.util.DownloadFile;
import com.kabelash.sg.util.ExternalStorage;
import com.kabelash.sg.R;

public class ZipDownloader extends Activity {

    protected ProgressDialog mProgressDialog;

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

        // Keep the screen (and device) active as long as this app is frontmost.
        // This is to avoid going to sleep during the download.
        getWindow().addFlags( WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON );
    }

    /**
     * Invoked when user presses "Start download" button.
     */
    public void startDownload( View v ) {
        String url = "http://sample.co.uk/sample.zip";
        new DownloadTask().execute( url );
    }

    /**
     * Background task to download and unpack .zip file in background.
     */
    private class DownloadTask extends AsyncTask<String,Void,Exception> {

        @Override
        protected void onPreExecute() {
            showProgress();
        }

        @Override
        protected Exception doInBackground(String... params) {
            String url = (String) params[0];

            try {
                downloadAllAssets(url);
            } catch ( Exception e ) { return e; }

            return null;
        }

    }

    //Progress window
    protected void showProgress( ) {
        mProgressDialog = new ProgressDialog(this);
        mProgressDialog.setTitle( R.string.progress_title );
        mProgressDialog.setMessage( getString(R.string.progress_detail) );
        mProgressDialog.setIndeterminate( true );
        mProgressDialog.setCancelable( false );
        mProgressDialog.show();
    }

    protected void dismissProgress() {
        // You can't be too careful.
        if (mProgressDialog != null && mProgressDialog.isShowing() && mProgressDialog.getWindow() != null) {
            try {
                mProgressDialog.dismiss();
            } catch ( IllegalArgumentException ignore ) { ; }
        }
        mProgressDialog = null;
    }



}

请不要忽视这个问题。提前谢谢,我的英语很抱歉。

您是否尝试过将您的异步任务代码带到您希望单击列表项的活动中,然后

switch(item.getItemId()){
        case R.id.update:
          String url = "http://sample.co.uk/sample.zip";
          new DownloadTask().execute( url );
            break;
    }
    return true;

将后台任务调用onclick?

“请忽略此问题”。现在我很困惑。你不想要答案吗?我不认为他知道他在最后一句的第二句写了什么。对不起,我的英语:)请给我一个这个问题的答案?谢谢你的想法。希望它能起作用。我试过之后会告诉你的。
switch(item.getItemId()){
        case R.id.update:
          String url = "http://sample.co.uk/sample.zip";
          new DownloadTask().execute( url );
            break;
    }
    return true;