【发布时间】:2014-08-26 09:27:53
【问题描述】:
我的 MainActivity 有两个 String 变量,即。 文件名 & url.
我尝试使用download manager。
我不知道如何从我的玩家活动中传递 文件名 String。
buttondownload = (TextView )findViewById(R.id.download);
buttondownload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DownloadHelper.addNewTask(Player.this, url,
new PreDownloadStatusListener() {
@Override
public void notFoundSDCard(int errorCode, String errorInfo) {
Toast.makeText(Player.this, "No SD Card", Toast.LENGTH_SHORT).show();
}
@Override
public void sdCardCannotWriteOrRead(int errorCode, String errorInfo) {
Toast.makeText(Player.this, "Not read and write SD card", Toast.LENGTH_SHORT).show();
}
@Override
public void moreTaskCount(int errorCode, String errorInfo) {
Toast.makeText(Player.this, "Task list is full", Toast.LENGTH_SHORT).show();
}
});
Intent intent1 = new Intent(Player.this, DownloadListActivity.class);
startActivity(intent1);
}
});
DownloadHelper.startAllTask(Player.this);
mReceiver = new DownloadReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction(DownloadValues.Actions.BROADCAST_RECEIVER_ACTION);
registerReceiver(mReceiver, filter);
他们从另一个公共类 DownloadUtils 调用文件名。我如何将 filname 传递给 DownloadUtils
我想将字符串从 Player 传递给 ViewHolder.java
package com.download.main;
public class ViewHolder {
public static final int KEY_URL = 0;
public static final int KEY_SPEED = 1;
public static final int KEY_PROGRESS = 2;
public static final int KEY_IS_PAUSED = 3;
public TextView titleText;
public ProgressBar progressBar;
public TextView speedText;
public ImageButton pauseButton;
public ImageButton deleteButton;
public ImageButton continueButton;
private boolean hasInited = false;
public ViewHolder(View parentView) {
if (parentView != null) {
titleText = (TextView) parentView.findViewById(R.id.title);
speedText = (TextView) parentView.findViewById(R.id.speed);
progressBar = (ProgressBar) parentView.findViewById(R.id.progress_bar);
pauseButton = (ImageButton) parentView.findViewById(R.id.btn_pause);
deleteButton = (ImageButton) parentView.findViewById(R.id.btn_delete);
continueButton = (ImageButton) parentView.findViewById(R.id.btn_continue);
hasInited = true;
}
}
public static HashMap<Integer, String> getItemDataMap(String url, String speed, String progress, String isPaused) {
HashMap<Integer, String> item = new HashMap<Integer, String>();
item.put(KEY_URL, url);
item.put(KEY_SPEED, speed);
item.put(KEY_PROGRESS, progress);
item.put(KEY_IS_PAUSED, isPaused);
return item;
}
public void setData(HashMap<Integer, String> item) {
if (hasInited) {
titleText.setText(///////**I want here my my string calle "filename" from player Activity**//////);
speedText.setText(item.get(KEY_SPEED));
String progress = item.get(KEY_PROGRESS);
if (TextUtils.isEmpty(progress)) {
progressBar.setProgress(0);
}
else {
progressBar.setProgress(Integer.parseInt(progress));
}
if (Boolean.parseBoolean(item.get(KEY_IS_PAUSED))) {
onPause();
}
}
}
public void onPause() {
if (hasInited) {
pauseButton.setVisibility(View.GONE);
continueButton.setVisibility(View.VISIBLE);
}
}
public void setData(String url, String speed, String progress) {
setData(url, speed, progress, false + "");
}
public void setData(String url, String speed, String progress, String isPaused) {
if (hasInited) {
HashMap<Integer, String> item = getItemDataMap(url, speed, progress, isPaused);
titleText.setText(///////**I want here my my string calle "filename" from player Activity**//////);
speedText.setText(speed);
if (TextUtils.isEmpty(progress)) {
progressBar.setProgress(0);
}
else {
progressBar.setProgress(Integer.parseInt(item.get(KEY_PROGRESS)));
}
}
}
}
【问题讨论】:
-
你的问题不清楚。请详细说明您的第三行。
-
我现在改了..你能检查一下github源码吗?请
标签: android string android-listview