2012-07-23 74 views
0

这是适用于Android的。在父母活动的列表视图项目中显示(“孩子”活动的)已检查项目的数量

首先,什么我想到一个例子:

Camping trip planner example

我怎么能达到这个效果?此列表视图的项目显示当您单击其中一个父列表视图项目时打开的子列表视图中未选中项目的数量。我应该为儿童活动使用静态类吗?或者第一个列表视图中有多少行?有人能给我一个例子吗?提前感谢你!

+0

只需制定计算项目总数/检查项数并将结果保存为两个静态值的方法即可。 – Slickelito 2012-07-23 14:26:06

+0

你能否详细说明一下?该方法应该在哪里(哪个班级,家长还是孩子)?它应该是无效的还是应该返回任何东西?在哪里应该将静态值存储在父类中?谢谢。 – Gigen 2012-07-24 09:20:06

回答

0

Slickelito,谢谢为了您的回答,我学到了一些关于抽象类的东西,但最终我遇到了我自己的解决方案:

我做了我自己的光标适配器,并且t他的方法 -

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文本绑定到此方法的返回值。它似乎工作,虽然我不完全确定效率。

0

我假设你有一个叫做Tasks的模型。

创建一个类似ProgressCounter的抽象类。 设置两个静态值:

public static int totalNumberOfTasks; 
public static int taskProgress; 

然后你做一个静态方法,并遍历它:

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

我希望这可以为您指出正确的方向:)

+0

嗯,看起来很有前途:)。我明天会给它一个镜头,当然如果它解决了我的问题,也会批准你的答案。无论哪种方式,非常感谢。 – Gigen 2012-07-24 20:24:20

相关问题