hi 问几个android开发的问题

hi 问几个问题
1. 如果在ProgressBar上显示数字,是否原生支持
2.
我有个下载的业务 在一个Activity中点下载的同时可以在另外一个Activity中显示现在进度:
我直接诶在Activity中new Thread来作的,这样好不好的,一般时用什么方法作? 这样性能是否过得去
看我红色标题部分,我是通过Thread while true,

  1. 我在已下载完毕的文件图标上放个勾勾,这个是图片合成作的,还是用android提供的工具做的?

[code="java"]
/**

  • */ package com.alibaba.cloudspace;

import java.util.ArrayList;
import java.util.List;

import android.app.TabActivity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.GestureDetector;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.TabHost.OnTabChangeListener;

public class TransStatusActivity extends TabActivity implements OnTabChangeListener {

private GestureDetector             gestureDetector;
private UpdateProgressBarHandler    progressBarHandler;
private UpdateDownloadFilesHandler  downloadFilesHandler;
private ProgressBarListAdapter      adapter                 = null;
private DownloadCompleteListAdapter downloadCompleteAdapter = null;
private ListView                    listView                = null;
private ListView                    listView2               = null;
private TabHost                     transTabhost;
private final String[]              TAB_IDS                 = new String[] { "TRANS_TAB1",
        "TRANS_TAB2"                                       };
private static FileMap              DOWNLOAD_FILES          = new FileMap();
private String                      email                   = "";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // TODO Get email.
    // email = getIntent().getExtras().getString("");

    gestureDetector = new GestureDetector(this, new CLGestureDetector(this));

    transTabhost = this.getTabHost();
    LayoutInflater.from(this).inflate(R.layout.trans_status, transTabhost.getTabContentView(),
            true);

    transTabhost.addTab(transTabhost.newTabSpec(TAB_IDS[0]).setIndicator(
            createTabTextView(R.string.app_text_transfer)).setContent(R.id.transfer_tab));

    transTabhost.addTab(transTabhost.newTabSpec(TAB_IDS[1]).setIndicator(
            createTabTextView(R.string.app_text_transfer_finish)).setContent(
            R.id.transfer_finish_tab));

    // TODO 载入未完成的下载列表
    progressBarHandler = new UpdateProgressBarHandler();
    downloadFilesHandler = new UpdateDownloadFilesHandler();

    adapter = new ProgressBarListAdapter(this, getTransStatusList());

    listView = (ListView) findViewById(R.id.trans_status_list);
    listView.setAdapter(adapter);

   [color=red][b] new UpdateProgressBarThread().start();
    new UpdateDownloadFileListThread().start();[/b][/color]
    downloadCompleteAdapter = new DownloadCompleteListAdapter(this, DOWNLOAD_FILES.get(email));

    listView2 = (ListView) findViewById(R.id.download_complete_list);
    listView2.setAdapter(downloadCompleteAdapter);

    transTabhost.setOnTabChangedListener(this);
}

。。。。
private List getTransStatusList() {
List transStatus = new ArrayList();

    for (int i = 0; i < FileListActivity.downloading.size(); i++) {
        FileDownloaderTask t = FileListActivity.downloading.get(i);
        if (t.isCompleted()) {
            DOWNLOAD_FILES.add(email, t.getFile());
            downloadFilesHandler.sendMessage(new Message());

            FileListActivity.downloading.remove(i--);
            continue;
        }

        TransStatus s = new TransStatus();
        s.setFid(t.getFile().getNodeId());
        s.setTitle(t.getFile().getFileName());
        s.setPercent(t.getPercent());

        Log.d("DEBUG-TRANS-STATUS", "Percent:" + s.getPercent() + ", has read:"
                + t.getHasReadSize() + ", full size:" + t.getFile().getFullSize());
        transStatus.add(s);
    }

    return transStatus;
}

class UpdateProgressBarThread extends Thread {
    public void run() {
        while (true) {
            Message msg = new Message();
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {

            }

            progressBarHandler.sendMessage(msg);

            int i = 0;
            for (FileDownloaderTask f : FileListActivity.downloading) {
                if (f.isCompleted())
                    i++;
            }

            Log.e("", "Completed:" + i + ", downloading size:"
                    + FileListActivity.downloading.size());
            if (i >= FileListActivity.downloading.size())
                break;
        }
    };
}

class UpdateDownloadFileListThread extends Thread {

    public void run() {
        Message msg = new Message();
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {

        }

        downloadFilesHandler.sendMessage(msg);
    };
}

class UpdateProgressBarHandler extends Handler {

    @Override
    public void handleMessage(Message msg) {
        adapter = new ProgressBarListAdapter(TransStatusActivity.this, getTransStatusList());

        listView = (ListView) findViewById(R.id.trans_status_list);
        listView.setAdapter(adapter);
    }
}

class UpdateDownloadFilesHandler extends Handler {

    @Override
    public void handleMessage(Message msg) {
        downloadCompleteAdapter = new DownloadCompleteListAdapter(TransStatusActivity.this,
                DOWNLOAD_FILES.get(email));

        listView2 = (ListView) findViewById(R.id.download_complete_list);
        listView2.setAdapter(downloadCompleteAdapter);
    }
}

@Override
public void onTabChanged(String tabId) {

}

private TextView createTabTextView(int rid) {
    TextView txtTabInfo = new TextView(this);
    txtTabInfo.setText(getResources().getString(rid));
    txtTabInfo.setPadding(0, 5, 0, 0);
    txtTabInfo.setTextSize(11);

    txtTabInfo.setBackgroundResource(R.drawable.tab_normal);
    txtTabInfo.setTextColor(Color.DKGRAY);
    txtTabInfo.setGravity(Gravity.CENTER);
    txtTabInfo.setHeight(39);

    return txtTabInfo;

}

}

[/code]

1个回答

  1. Progress Bar 是不带数字显示的
  2. 最好不要直接使用 new Thread 来完成下载,建议你使用 AsyncTask 去实现
  3. 没看到你的效果图,不知道你是指什么?但是我觉得应该是这样的:文件正在下载时,你显示的是一个图标,而当文件下载完成时,用另外一个图标来代替之前的图标
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问