0
嗨,我已經創建了下載過程活動,並且它在按鈕點擊上運行。此活動在listitem點擊下打開。但是現在我想在lisitem單擊下運行下載過程,單擊按鈕單擊。在MainActivity.java在listitem上需要幫助點擊android
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;
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
switch(item.getItemId()){
case R.id.update:
Intent intent = new Intent(this, ZipDownloader.class);
startActivity(intent);
break;
}
return true;
}
請不要忽略這個問題。預先感謝併爲我的英語感到遺憾。
「請忽略此問題」。現在我只是困惑。 –
你不想要一個答案? – Pavlos
我不知道他知道他在第二句話中寫了什麼。 – Leandros