我正在尝试使用ParsequeryAdapter在列表视图中显示用户名和照片.我有以下课程:User和Post.
我在这里设置:
String[] postsObjectIDs = some_string_arrayParsequeryAdapter<Post> adapter = new ParsequeryAdapter<Post>(getActivity(), new ParsequeryAdapter.queryFactory<Post>() { public Parsequery<Post> create() { Parsequery<Post> query = Post.getquery(); query.include("User"); query.whereContainedIn("objectID", Arrays.asList(postsObjectIDs)); return query; }});adapter.setTextKey("username");adapter.setimageKey("photo");adapter.setPlaceholder(getResources().getDrawable(R.drawable.some_drawable));ListVIEw ListVIEw = (ListVIEw) rootVIEw.findVIEwByID(R.ID.post_List_vIEw);ListVIEw.setAdapter(adapter);
Post类有一个名为photo的列,而User类有一个名为username的列.列表视图未显示用户名.
我必须实现自定义适配器吗?
有快速解决方法吗?
解决方法:
我在解析帮助论坛上找到了答案:
ParseQueryAdapter setTextKey for relational object
接受的答案说使用自定义的ParsequeryAdapter< T>.并覆盖getItemVIEw.
例如,在片段的onCreateVIEw方法中,我初始化了适配器并进行了设置(postsObjectIDs是某些String []):
PostVIEwListVIEwAdapter adapter = new PostVIEwListVIEwAdapter(getActivity(), postsObjectIDs);ListVIEw ListVIEw = (ListVIEw) rootVIEw.findVIEwByID(R.ID.post_List_vIEw);ListVIEw.setAdapter(adapter);
这是我的适配器(PostVIEwListVIEwAdapter):
public class PostVIEwListVIEwAdapter extends ParsequeryAdapter<Post> { private final String[] mpostsObjectIDs; public PostVIEwListVIEwAdapter(Context context, final String[] postsObjectIDs) { super(context, new ParsequeryAdapter.queryFactory<Post>(){ public Parsequery<Post> create() { Parsequery<Post> query = Post.getquery(); query.include("User"); query.whereContainedIn("objectID", Arrays.asList(postsObjectIDs)); return query; } }); this.mpostsObjectIDs = postsObjectIDs; } @OverrIDe public VIEw getItemVIEw(Post post, VIEw v, VIEwGroup parent) { if(v == null) { v = VIEw.inflate(getContext(), R.layout.List_item_post_vIEw, null); } super.getItemVIEw(post, v, parent); final TextVIEw usernameTextVIEw = (TextVIEw) v.findVIEwByID(R.ID.username_text_vIEw); post.getCreator().fetchIfNeededInBackground(new GetCallback<ParseUser>() { @OverrIDe public voID done(ParseUser user, ParseException e) { usernameTextVIEw.setText(user.getUsername()); } }); return v; }}
总结 以上是内存溢出为你收集整理的如何使用ParseQueryAdapter(Android Parse)从另一个类获取数据全部内容,希望文章能够帮你解决如何使用ParseQueryAdapter(Android Parse)从另一个类获取数据所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)