小编yvi*_*yvi的帖子

Android:具有处理程序和runnable的ListView中的多个计时器.2个问题

我正在创建一个包含带有2列的ListView的应用程序.在第一列上应显示倒计时,在第二列上显示一个附加文本,用于说明倒计时的内容.下面你看到我的代码有效......或多或少.我有一个包含多行的列表视图,计时器正在滴答作响.一个问题是:我的runnable中的set.Text()似乎覆盖了所有行.例如,对于第1行可运行也将文本设置为第2行和第3行,对第2行可运行也将文本设置为1和3,依此类推.这会导致第一列闪烁(具有正确的值和其他行的值).如何为列表视图中的特定行设置文本?

下一个问题:即使我从处理程序中删除回调,runnable也会继续运行.但是当活动处于后台或关闭时,不需要计时器滴答,我不想浪费系统资源.

我的活动:

public class TimerActivity extends ListActivity {

MyTimerAdapter myTimerAdapter = null;
ArrayList<Long> timerList = new ArrayList<Long>();
ArrayList<String> textList = new ArrayList<String>();

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.listactivity);

    myTimerAdapter = new MyTimerAdapter(this, R.layout.row, R.id.tv_timer, R.id.tv_text);
    setListAdapter(myTimerAdapter);
}

@Override
protected void onResume() {
    super.onResume();
    refreshView();
}

@Override
protected void onPause() {
    myTimerAdapter.clear();
    myTimerAdapter.notifyDataSetChanged();
    super.onPause();
}

private void refreshView() {

    myTimerAdapter.clear();
    timerList.clear();
    textList.clear();

    // some code to read database and fill 
    // array timerList with a long value (used …
Run Code Online (Sandbox Code Playgroud)

android listview timer handler runnable

3
推荐指数
1
解决办法
5532
查看次数

Android 应用仅在发布 APK 时崩溃

我有一个奇怪的问题。我构建了一个在调试模式下运行良好的应用程序(直接调试到我的手机并在我的手机上安装了调试 APK)但是如果我使用发布版本 APK,该应用程序会在某一时刻崩溃。我发现应用程序在发布 APK 时崩溃,但我不知道为什么以及我能做什么:

protected final String TABLE = "done";
protected final String COL_ID = "_id";
protected final String COL_TASK = "taskid";
protected final String COL_DATE = "donedate";

protected String getLastDoneDate(String id) {
    String date = "";

    String filter = COL_TASK + " LIKE ?";
    String[] filterArgs = new String[] {id};
    String sortOrder = COL_DATE + " DESC";
    String[] columns = new String[] {COL_DATE};
    Cursor c = MyTime.db.query(TABLE, columns, filter, filterArgs, null, null, sortOrder, "1");
    if (c.moveToFirst()) {
        date …
Run Code Online (Sandbox Code Playgroud)

android apk

1
推荐指数
1
解决办法
6443
查看次数

标签 统计

android ×2

apk ×1

handler ×1

listview ×1

runnable ×1

timer ×1