gpt4 book ai didi

java - 解析查询获取数据到列表

转载 作者:太空宇宙 更新时间:2023-11-04 13:41:43 27 4
gpt4 key购买 nike

我有一个列表参数列表列表,我试图将 sList 传递回其中。如何将数据获取到父类(super class)?

错误消息显示无法解析 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());
}


}
});

}
}

最佳答案

所有子类都可以访问父类(super class)的所有字段和方法(如果它们不是私有(private)的)。因此,就您的情况而言,您有两个选择:

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

编辑

我如何打造 super 类(class):

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

编辑第二

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

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

public List<Group> list;

@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 = new ArrayList<Group>();

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());
}
}
addGroups(sList);
Log.d("groups1", "Retrieved " + groupList.size() + " groups");
} else {
Log.d("groups1", "Error: " + e.getMessage());
}


}
});

}
}

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

关于java - 解析查询获取数据到列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31193669/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com