0

对于 Android 应用程序...我在调用自定义 ListActivity 的 Activity 上有一个按钮。这个 ListActivity 有两行文本和一个复选框。调用时,ListActivity 在设备上打开一个 XML 文件 ( local.xml) 。此 XML 文件包含 Web 上的目标 XML 文件列表。如果设备上存在该文件,则选中 ListActivity 上的复选框,否则不选中。

当 ListItem 被按下时,它会检查目标文件是否存在于设备上——如果存在,它会显示一个对话框,询问是否要覆盖。如果文件不存在,或者如果他们选择覆盖,则会在进入 Internet 并抓取一组文件时显示一个进度对话框(目标 XML 文件包含要收集的 JPegs 列表)。

下载 JPegs 后,我更改进度消息以显示是否所有 JPegs 都已下载。它睡了几秒钟,然后消失了。

以上所有工作。

我的问题是:

  1. 完成后,如何根据是否下载所有 JPegs 来设置与按下的项目关联的复选框?

  2. 我真的想要一个三态指示器而不是一个二进制的复选框,除非我可以将颜色更改为黄色。我应该在这里使用更好的小部件吗?

相关代码如下(如果您需要查看更多信息,请告诉我)

初始活动:

public class RRS_Preferences extends Activity {
    onCreate(yadda, yadda)  {
}

public void Button_Listener(View view)  {
    /* open up the ListView Activity */
    Intent myIntent = new Intent();
    myIntent.setClassName("com.sinisterlabs.mypackage", "com.sinisterlabs.mypackage.Download_List");
    startActivity(myIntent);
    }
}

自定义列表活动:

public class Download_List extends ListActivity {
    List<Location>loc_list = new ArrayList<Location>();

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setListAdapter(new RRSList_ArrayAdapter(this));
        selection = (TextView)findViewById(R.id.tableRow1);

        /* Open the "local.xml" file, pull from it the list of files that need to go
        onto the ListActivity. For each file, I add it to the List.  */
        loc_list.add(new Location(stringLocalFilename, stringURL, booleanIsPresent));
    }

    protected void onListItemClick(final ListView parent, final View v, int position, long href)    {
        if (fileLocalFile.exists)   {
            subDownloadJPegs(fileLocalFile);

        } else {    // Ask to download or not?
            AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
            alertBuilder.setMessage("Are you sure you want to OverWrite this file and all of its image files?")
                .setCancelable(false)
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                        subDownloadJPegs(fileLocalFile);
                        }
                    });
                .setNegativeButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                        Toast.makeText(getApplicationContext(), "OverWrite Operation Cancelled...", Toast.LENGTH_LONG).show();
                        }
                    });
            AlertDialog alert = alertBuilder.create();
            alert.show();
        }
    }

    private void subDownloadJPegs(fileLocalFile)    {
        progDialog = new ProgressDialog(this);
        progDialog.setCancelable(true);
        progDialog.setMessage("Downloading files for " + fileLocalFile.toString() + "...");
        progDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        progDialog.setProgress(0);
        /* open up this file and count the number of JPegs to be downloaded */
        progDialog.setMax(intMax);
        progDialog.setMessage("Downloading Sign Files for " + RuleSetName + "...");
        progDialog.show();

        /* background thread to update progress bar */
        Thread background = new Thread (new Runnable() {
        @Overide
        public void run() {
            /* Inside a loop, download each file, increment the progress bar as we do */
            progressHandler.sendMessage(progressHandler.obtainMessage());
        }
        background.start();
    }

    Handler progressHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            progDialog.incrementProgressBy(1);
        }
}

列表项布局 XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:clickable="false"
        android:focusable="false"
        android:gravity="center" />

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView android:id="@+id/text1" 
            android:layout_width="fill_parent" 
            android:layout_height="20dp" 
            android:textSize="18dp"></TextView>

        <TextView android:id="@+id/text2" 
            android:layout_width="fill_parent" 
            android:layout_height="15dp"
            android:textSize="13dp"></TextView>

    </LinearLayout>
</LinearLayout>

谢谢!!!

4

1 回答 1

0

好,我知道了。问题出在我拨打电话以关闭对话框的位置。它最终在一个 catch 语句中并且从未执行。在解决这个问题时,我还参数化了对处理程序的调用,这让事情变得更加清晰。

呼!:-)

于 2012-09-19T22:03:52.087 回答