2014-10-06 109 views
-1

我有一個列表視圖,它使用parse.com中的parseobjects填充。一切工作正常,但我想只填充一些項目到列表視圖。這是我的適配器。Android ListView只加載一些項目

我只想加載註釋如果它們在解析的「狀態」列下有當前狀態。

public class MyCustomAdapter extends ParseQueryAdapter<ParseObject> { 

    public MyCustomAdapter(Context context) { 
     super(context, "Comments", R.layout.comments_listview_item); 
    } 

    @Override 
    public View getItemView(final ParseObject comment, View view, ViewGroup parent) { 
     view = View.inflate(getApplicationContext(), R.layout.comments_listview_item, null); 
     mListViewReferences(view); 

     /** 
     * Only display the comments that belong to this status 
     */ 
     final ParseQuery commentQuery = new ParseQuery("Comments"); 
     commentQuery.whereEqualTo("Status", status); 
     commentQuery.findInBackground(new FindCallback<ParseObject>() { 
      @Override 
      public void done(List<ParseObject> comments, ParseException e) { 
       for (ParseObject c: comments){ 
        commenttext.setText(c.getString("Comment")); 
        commentersUserName.setText(c.getString("Commenter")); 

       } 
      } 
     }); 

     return super.getItemView(comment, view, parent); 
    } 

    // Set References 
    private void mListViewReferences(final View view) { 
     commentersUserName = (TextView) view.findViewById(R.id.commentersUserName); 
     commenttext = (TextView) view.findViewById(R.id.commenttext); 
    } 
} 

我在想,也許的改變適配器來擴展ArrayAdapter和適配器外使用查詢和取結果的查詢,並賦予它傳遞給適配器。但我之前,有可能是使用parsequeryadapter

回答

0

的方式,您應該使用QueryFactory從參數超

例子:https://parse.com/tutorials/parse-query-adapter

public CustomAdapter(Context context) { 
// Use the QueryFactory to construct a PQA that will only show 
// Todos marked as high-pri 
super(context, new ParseQueryAdapter.QueryFactory<ParseObject>() { 
    public ParseQuery create() { 
    ParseQuery query = new ParseQuery("Todo"); 
    query.whereEqualTo("highPri", true); 
    return query; 
    } 
}); 
} 
+0

不知道解析了比他們表現出的那些更多的教程在https://parse.com/tutorials/上 – user123859 2014-10-06 19:23:11