Android应用 - 我该如何更新我的列表项? [英] Android app - how do I update my ListItem?

查看:225
本文介绍了Android应用 - 我该如何更新我的列表项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关Android应用程序......我有一个调用自定义ListActivity的活动按钮。这ListActivity具有文本和一个复选框的两行。调用时,ListActivity开辟了一个XML文件中的设备上(那个local.xml )。此XML文件中包含的网页上目标XML文件的列表。如果该文件在设备上存在,就ListActivity的复选框被选中,否则就不是。

For an Android app...I have a button on an Activity that calls a custom ListActivity. This ListActivity has two lines of text and a checkbox. When invoked, the ListActivity opens up an XML file on the device (local.xml) . This XML file contains a list of target XML files on the web. If the file exists on the device, the checkbox on the ListActivity is checked, otherwise it isn't.

在该列表项为pressed,它会检查如果目标文件上存在设备,如果是的话,它会显示一个对话框,询问是否要覆盖。如果该文件不存在,或者如果他们选择了覆盖,是因为它进入到互联网,并抓住一组文件(目标XML文件包含JPEG文件的列表,收集)。

When the ListItem is pressed, it checks to see if the target file exists on the device-if it does, it displays a dialog box asking if they want to overwrite. If the file doesn't exist, or if they chose to overwrite, a progress dialog is displayed as it goes to the internet and grabs a set of files (the target XML file contains a list of JPegs to gather).

下载JPEG文件后,我改变对正在进行的消息来显示所有的JPEG文件是否下载与否。它睡了几秒钟,然后在前看不见。

After downloading the JPegs, I change the message on the progress to show whether all the JPegs downloaded or not. It sleeps for a few seconds, then disapears.

所有上述作品。

我的问题是:


  1. 完成后,如何设置与pressed项目相关的复选框,根据是否所有下载的JPEG文件或不?

  1. After completion, how do I set the checkbox associated with the pressed item, based on whether all of the JPegs downloaded or not?

我真的想一个三态的指标,而不是一个复选框,这是二进制的,除非我可以改变颜色为黄色。有没有更好的部件,我应该使用吗?

I'd really like a tri-state indicator instead of a checkbox, which is binary, unless I could change the color to yellow. Is there a better widget I should be using here?

Relvant code如下(让我知道如果你需要查看更多)

Relvant code follows (let me know if you need to see more)

最初的活动:

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);
    }
}

自定义列表活动:

Custom List Activity:

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:

List Item Layout 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>

谢谢!

推荐答案

OK,我知道了。问题是,我打的电话,以关闭该对话框。它结束了一个catch语句内,从来没有执行。在修复此,我也我的参数调用处理程序,这让事情更清晰。

OK, I got it. the problem was where I placed the call to dismiss the dialog box. It ended up inside a catch statement and was never executing. In fixing this, I also parameterized my calls to the handler, which made things clearer.

Wheh!
: - )

Wheh! :-)

这篇关于Android应用 - 我该如何更新我的列表项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆