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