对于Android应用...我在Activity上有一个按钮,用于调用自定义ListActivity。此ListActivity有两行文本和一个复选框。调用时,ListActivity会在设备上打开XML文件(local.xml
)。此XML文件包含Web上的目标XML文件列表。如果设备上存在该文件,则会检查ListActivity上的复选框,否则不会。
按下ListItem时,它会检查设备上是否存在目标文件 - 如果存在,则会显示一个对话框,询问是否要覆盖。如果文件不存在,或者他们选择覆盖,则会在进入Internet并显示一组文件时显示进度对话框(目标XML文件包含要收集的JPegs列表)。
下载JPegs后,我更改了进度上的消息,以显示是否已下载所有JPegs。它睡了几秒钟,然后消失了。
以上所有作品。
我的问题是:
完成后,如何设置与按下的项目关联的复选框,具体取决于是否已下载所有JPegs?
我真的很喜欢三态指示器而不是复选框,它是二进制的,除非我可以将颜色更改为黄色。我应该在这里使用更好的小部件吗?
以下是Relvant代码(如果您需要了解更多信息,请告诉我)
初始活动:
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>
感谢!!!
答案 0 :(得分:0)
好的,我明白了。问题出在我放置调用以解除对话框的地方。它最终进入了一个catch语句,并且从未执行过。在解决这个问题时,我还将我对调用程序的调用参数化,这使得事情变得更加清晰。
Wheh! : - )