这是针对安卓的。
首先,我想到的一个例子:
我怎样才能达到这种效果?此列表视图的项目显示当您单击父列表视图的项目之一时打开的子列表视图中未选中项目的数量。我应该为子活动使用静态类吗?或者与第一个列表视图中的行一样多的实例?有人可以给我一个例子吗?非常感谢您!
I'm assuming you have a model called something like Tasks.
Make an abstract class called something like ProgressCounter. Setup two static values :
public static int totalNumberOfTasks;
public static int taskProgress;
Then you make a static method and iterate over it :
public static void countProgress(ArrayList<Tasks> allTasks){
ProgressCounter.totalNumberOfTasks = allTask.size();
int taskProgress = 0;
for(Task task : allTasks){
if(task.isCompleted());
taskProgress++;
}
ProgressCounter.taskProgress = taskProgress;
}
I hope this can point you in the right direction :)
Slickelito,感谢您的回答,我学到了一些关于抽象类的东西,但最后我找到了自己的解决方案:
我制作了自己的光标适配器和这种方法-
public int getChildCount(long lvPhase) {
String phase = Long.toString(lvPhase);
String[] projection = { FlightBundleDatabase.ID };
String[] selectionArgs = { Long.toString(mAircraft), phase };
int count = 0;
CursorLoader cursorLoader = new CursorLoader(mContext, FlightBundleProvider.CONTENT_URI_CHECKLISTS, projection, "aircraft_id = ? AND phase = ?", selectionArgs, null);
Cursor cursor = cursorLoader.loadInBackground();
int cCount = cursor.getCount();
if (cursor.moveToFirst()) {
for (int i = 0; i < cCount; i++) {
long currentItem = cursor.getLong(cursor.getColumnIndexOrThrow(FlightBundleDatabase.ID));
if (mSettingsActivity.contains(phase + currentItem)) {
count++;
}
cursor.moveToNext();
}
}
cursor.close();
return count;
}
然后我将计数器 TextView 文本绑定到此方法的返回值。它似乎工作,虽然我不完全确定效率。