解析查询获取数据到列表

时间:2015-07-02 20:02:26

标签: java android parse-platform

我有一个列表参数列表列表,我试图将sList传回。如何将数据提供给超类?

错误消息显示无法解析this.addGroups。我已经尝试创建一个子组列表并分配它,我尝试直接使用List.add进行分配

更新完整课程

public class GroupActivity extends ActionBarActivity {
Context context;
RecyclerView groupRecyclerView;
GroupAdapter groupAdapter;
private Toolbar toolbar;

public List<Group> list = new ArrayList<>();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_group);

    toolbar = (Toolbar) findViewById(R.id.app_bar);
    setSupportActionBar(toolbar);

    getSupportActionBar().setDisplayShowHomeEnabled(true);

    getSupportActionBar().setTitle("POLICE APP");

    context = this;
    Helpers.setTabs(context, this, 2);

    groupRecyclerView = (RecyclerView) findViewById(R.id.ui_Groups_RecyclerView);
    this.GetData();
    groupAdapter = new GroupAdapter(this, list);

    groupRecyclerView.setAdapter(groupAdapter);
    groupRecyclerView.setLayoutManager(new LinearLayoutManager(this));


}

public void addGroups(List<Group> grps) {

    this.list = grps;
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_group, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

public void GetData() {
    ParseQuery<ParseObject> query = ParseQuery.getQuery("Group");

    query.findInBackground(new FindCallback<ParseObject>() {
        List<Group> sList;

        public void done(List<ParseObject> groupList, ParseException e) {
            if (e == null) {
                for (int i = 0; i < groupList.size(); i++) {
                    try {
                        Group grp1 = new Group("1", groupList.get(i).getString("Name"), " Turn in your time sheets", "d");
                        sList.add(grp1);
                        Log.d("group1:", "inserted the group");
                    } catch (Exception c) {
                        c.printStackTrace();
                        Log.d("group1:", c.getMessage().toString());
                    }
                }
                this.addGroups.add(sList);
                Log.d("groups1", "Retrieved " + groupList.size() + " groups");
            } else {
                Log.d("groups1", "Error: " + e.getMessage());
            }


        }
    });

}
}

2 个答案:

答案 0 :(得分:0)

如果子类不是私有的,那么所有子类都可以访问超类中的所有字段和方法。因此,在您的情况下,您有两种选择:

# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution:
    # @param {TreeNode} root
    # @return {integer}
    def minDepth(self, root):
        if root is None:
            return 0

        if root.left is None:
            return 1 + self.minDepth(root.right)

        if root.right is None:
            return 1 + self.minDepth(root.left)

        return 1 + min(self.minDepth(root.left), self.minDepth(root.right))

修改

我如何制作超级课程:

setList(clist); // I suppose list is private and in super class you made a setter for it

// or

this.list=cList;  // if list isn't private

编辑No2

受你编辑的问题(:)的启发,我改变了你的代码,它应该工作。测试并发布结果。

public class SuperClass{
   private List<Group> list;
   // class's methods
   public void setList(ArrayList<Group> list){
      this.list = list;
   }
}

你犯了一些明显的编码错误,所以如果我是对的那就是问题。试试吧。

答案 1 :(得分:0)

我发现了这个问题。我需要在for循环后添加此代码              groupAdapter = new GroupAdapter(context,list);

    groupRecyclerView.setAdapter(groupAdapter);

基本上,Parse返回异步,视图没有新内容。只需在for循环后更新视图