ParseQueryAdapter不取的物品 [英] ParseQueryAdapter not fetching the items

查看:141
本文介绍了ParseQueryAdapter不取的物品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ListView和我使用Parse.com数据,我使用的是ParseQueryAdapter泵ListView控件。但我没有看到数据由适配器读​​取。

这是我的code ..

 公共类MainActivity扩展ActionBarActivity {    私人的ArrayList<日期和GT; dateHeaders;
    私人的HashMap<日期,ArrayList的<会议>> dateContent;    私人ParseQueryAdapter<会议> sessionsQueryAdapter;    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);
        Log.d(测试,查询);
        Parse.enableLocalDatastore(本);
        Parse.initialize(这一点,XXX,XXX);
        ParseObject.registerSubclass(Sessions.class);        // sessionHeaderFetch();
        ParseQueryAdapter.QueryFactory<会议>厂=新ParseQueryAdapter.QueryFactory<会议>(){
            @覆盖
            公共ParseQuery<会议>创建() {
                ParseQuery<会议>查询= Sessions.getQuery();
                query.include(的sessionId);
                query.include(位置);
                Log.d(测试,查询);
                返回查询;
            }
        };        sessionsQueryAdapter =新ParseQueryAdapter<会议>(这一点,工厂){
            公共查看getItemView(会话的会话,查看视图的ViewGroup父){
                如果(查看== NULL){
                    鉴于= View.inflate(的getContext(),R.layout.session_list_item,NULL);
                }
                Log.d(测试,适配器);
                TextView的teamName =(TextView中)view.findViewById(R.id.teamName);
                TextView的位置=(TextView中)view.findViewById(R.id.location);
                TextView的时间=(TextView中)view.findViewById(R.id.netsTime);
                TextView的插槽=(TextView中)view.findViewById(R.id.slots);
                TextView的bookedSlots =(TextView中)view.findViewById(R.id.players);
                TextView的openSlots =(TextView中)view.findViewById(R.id.openSlots);
                teamName.setText(sessions.getSessionId());
                location.setText(sessions.getLocation());
                time.setText((CharSequence的)sessions.getNetsDate());
                slots.setText(sessions.getSlots());
                bookedSlots.setText(sessions.getOpenSlots());
                openSlots.setText(sessions.getOpenSlots());
                返回视图。
            }
        };        sessionsQueryAdapter.setAutoload(假);
        sessionsQueryAdapter.setPaginationEnabled(假);        ListView控件的ListView =(ListView控件)findViewById(R.id.expandableListView);
        sessionsQueryAdapter.setTextKey(的sessionId);
        listView.setAdapter(sessionsQueryAdapter);    }
}

与其他的getter和setter沿着我有我的解析模型类中下面的方法为好。

 公共静态ParseQuery<会议> getQuery(){
        Log.d(测试,内查询);
        返回ParseQuery.getQuery(Sessions.class);
    }

解析类

  @ParseClassName(会议)
公共类会话扩展的parseObject {
    公开会议(){    }    公共字符串的sessionId;
    公共字符串位置;
    公共字符串netNo;
    公共字符串userid;
    公众诠释插槽;
    公众诠释openSlots;
    公开日期netsDate;    公共字符串getSessionId(){
        返回的getString(的SessionID);
    }    公共无效setSessionId(字符串的sessionId){
        把(的SessionID的sessionId);
    }    公共字符串的getLocation(){
        返回的getString(位置);
    }    公共无效的setLocation(字符串位置){
        把(位置,位置);
    }    公共字符串getNetNo(){
        返回的getString(NetNo);
    }    公共无效setNetNo(字符串netNo){
        把(NetNo,netNo);
    }    公共字符串getUserId(){
        返回的getString(用户ID);
    }    公共无效setUserId(字符串userid){
        把(用户ID,用户id);
    }    公众诠释getSlots(){
        返回调用getInt(老虎机);
    }    公共无效setSlots(INT插槽){
        把(老虎机,插槽);
    }    公众诠释getOpenSlots(){
        返回调用getInt(OpenSlots);
    }    公共无效setOpenSlots(INT openSlots){
        把(OpenSlots,openSlots);
    }    公开日期getNetsDate(){
        返回GETDATE(NetsDate);
    }    公共无效setNetsDate(日期netsDate){
        把(NetsDate,netsDate);
    }    公共静态ParseQuery<会议> getQuery(){
        Log.d(测试,内查询);
        返回ParseQuery.getQuery(Sessions.class);
    }
}


解决方案

您与我聊天共享你的code之后,我相信这是对你最好的解决方案:
您parseIO改成这样:

 公共类ParseIO {公共无效sessionFetch(日期头,最终ParseIOListener<会议>监听){
     ParseQuery<会议>查询= ParseQuery.getQuery(Sessions.class);
     query.whereEqualTo(NetsDate,标题);
     最终的ArrayList<会议> sessionsData =新的ArrayList<会议>();
     query.findInBackground(新FindCallback<会议>(){
       @覆盖
       公共无效完成(列表<会议> sessionsObjects,com.parse.ParseException E){
            如果(E == NULL){
               对于(会话的会话:sessionsObjects){
                  sessionsData.add(会话);
               }
               listener.onDataRetrieved(sessionsData);
            }其他{
                listener.onDataRetrieveFail(E);
            }
         }
     });
 } 公共无效sessionHeaderFetch(最终ParseIOListener<日期和GT;监听){      Log.d(测试,会话获取条目);
      ParseQuery<会议>查询= ParseQuery.getQuery(Sessions.class);
      最终的ArrayList<日期和GT; sessionHeaders =新的ArrayList<日期及GT;();
      query.findInBackground(新FindCallback<会议>(){
           @覆盖
           公共无效完成(列表<会议> sessionsObjects,com.parse.ParseException E){
                如果(E == NULL){
                    Log.d(测试,检索 - 你好+ sessionsObjects.size()+会议);
                    对于(会话的会话:sessionsObjects){
                        sessionHeaders.add(session.getNetsDate());
                    }
                    Log.d(测试,解析取头+ sessionHeaders.size());
                    listener.onDataRetrieved(sessionHeaders);
                }其他{
                   Log.d(测试,错误:+ e.getMessage());
                   listener.onDataRetrieveFail(E);
                }
            }
       });  }  公共接口ParseIOListener< T> {
       无效onDataRetrieved(ArrayList的< T> listOfData);
       无效onDataRetrieveFail(ParseException的E);
  }
}

现在,如果你发现你的方法返回void。但需要一个接口。所以,当你调用这个方法,你可以设置界面,当它被称为它将包含您的数据
例如要获得头:

  sessionHeaderFetch(新ParseIOListener<日期及GT;(){
     @覆盖
     公共无效onDataRetrieved(ArrayList的<日期和GT; listOfData){
         //这里你有你的listOfData
     }     @覆盖
     公共无效onDataRetrieveFail(ParseException的E){
         //错误。登录出来,在这里处理它
     }
 });

I have a ListView and I am using Parse.com for data, I am using a ParseQueryAdapter to pump the ListView. But I don't see the data being fetched by the adapter.

here is my code..

public class MainActivity extends ActionBarActivity {

    private ArrayList<Date> dateHeaders;
    private HashMap<Date,ArrayList<Sessions>> dateContent;

    private ParseQueryAdapter<Sessions> sessionsQueryAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.d("test", "query");
        Parse.enableLocalDatastore(this);
        Parse.initialize(this, "xxx", "xxx");
        ParseObject.registerSubclass(Sessions.class);

        //sessionHeaderFetch();
        ParseQueryAdapter.QueryFactory<Sessions>  factory = new ParseQueryAdapter.QueryFactory<Sessions>(){
            @Override
            public ParseQuery<Sessions> create() {
                ParseQuery<Sessions> query = Sessions.getQuery();
                query.include("sessionId");
                query.include("Location");
                Log.d("test", "query");
                return query;
            }
        };

        sessionsQueryAdapter = new ParseQueryAdapter<Sessions>(this, factory){
            public View getItemView(Sessions sessions, View view, ViewGroup parent){
                if(view == null){
                    view = View.inflate(getContext(), R.layout.session_list_item, null);
                }
                Log.d("test", "adapter");
                TextView teamName = (TextView) view.findViewById(R.id.teamName);
                TextView location = (TextView) view.findViewById(R.id.location);
                TextView time = (TextView) view.findViewById(R.id.netsTime);
                TextView slots = (TextView) view.findViewById(R.id.slots);
                TextView bookedSlots = (TextView) view.findViewById(R.id.players);
                TextView openSlots = (TextView) view.findViewById(R.id.openSlots);
                teamName.setText(sessions.getSessionId());
                location.setText(sessions.getLocation());
                time.setText((CharSequence) sessions.getNetsDate());
                slots.setText(sessions.getSlots());
                bookedSlots.setText(sessions.getOpenSlots());
                openSlots.setText(sessions.getOpenSlots());
                return view;
            }
        };

        sessionsQueryAdapter.setAutoload(false);
        sessionsQueryAdapter.setPaginationEnabled(false);

        ListView listView = (ListView) findViewById(R.id.expandableListView);
        sessionsQueryAdapter.setTextKey("sessionId");
        listView.setAdapter(sessionsQueryAdapter);

    }
}

along with other getter and setters I have the following method as well inside my Parse Model class.

public static ParseQuery<Sessions> getQuery() {
        Log.d("test", "inside query");
        return ParseQuery.getQuery(Sessions.class);
    }

Parse class

@ParseClassName("Sessions")
public class Sessions extends ParseObject {
    public Sessions(){

    }

    public String sessionId;
    public String location;
    public String netNo;
    public String userId;
    public int slots;
    public int openSlots;
    public Date netsDate;

    public String getSessionId() {
        return getString("SessionId");
    }

    public void setSessionId(String sessionId) {
        put("SessionId", sessionId);
    }

    public String getLocation() {
        return getString("Location");
    }

    public void setLocation(String location) {
        put("Location", location);
    }

    public String getNetNo() {
        return getString("NetNo");
    }

    public void setNetNo(String netNo) {
        put("NetNo", netNo);
    }

    public String getUserId() {
        return getString("UserId");
    }

    public void setUserId(String userId) {
        put("UserId", userId);
    }

    public int getSlots() {
        return getInt("Slots");
    }

    public void setSlots(int slots) {
        put("Slots", slots);
    }

    public int getOpenSlots() {
        return getInt("OpenSlots");
    }

    public void setOpenSlots(int openSlots) {
        put("OpenSlots", openSlots);
    }

    public Date getNetsDate() {
        return getDate("NetsDate");
    }

    public void setNetsDate(Date netsDate) {
        put("NetsDate", netsDate);
    }

    public static ParseQuery<Sessions> getQuery() {
        Log.d("test", "inside query");
        return ParseQuery.getQuery(Sessions.class);
    }
}

解决方案

After you shared your code with me in the chat, I believe this is the best solution for you: Change your parseIO to this:

public class ParseIO {  

public void sessionFetch(Date headers, final ParseIOListener<Sessions> listener){ 
     ParseQuery<Sessions> query = ParseQuery.getQuery(Sessions.class); 
     query.whereEqualTo("NetsDate",headers); 
     final ArrayList<Sessions> sessionsData = new ArrayList<Sessions>(); 
     query.findInBackground(new FindCallback<Sessions>() { 
       @Override 
       public void done(List<Sessions> sessionsObjects, com.parse.ParseException e) { 
            if (e == null) { 
               for (Sessions session : sessionsObjects) { 
                  sessionsData.add(session); 
               } 
               listener.onDataRetrieved(sessionsData); 
            } else { 
                listener.onDataRetrieveFail(e); 
            } 
         } 
     });  
 } 

 public void sessionHeaderFetch(final ParseIOListener<Date> listener){ 

      Log.d("test", "session fetch entry"); 
      ParseQuery<Sessions> query = ParseQuery.getQuery(Sessions.class); 
      final ArrayList<Date> sessionHeaders = new ArrayList<Date>(); 
      query.findInBackground(new FindCallback<Sessions>() { 
           @Override 
           public void done(List<Sessions> sessionsObjects, com.parse.ParseException e) { 
                if (e == null) { 
                    Log.d("test", "Retrieved -- hello" + sessionsObjects.size() + " sessions"); 
                    for (Sessions session : sessionsObjects) { 
                        sessionHeaders.add(session.getNetsDate()); 
                    } 
                    Log.d("test", "Parse fetched headers" + sessionHeaders.size()); 
                    listener.onDataRetrieved(sessionHeaders); 
                } else { 
                   Log.d("test", "Error: " + e.getMessage()); 
                   listener.onDataRetrieveFail(e); 
                } 
            } 
       }); 

  } 

  public interface ParseIOListener<T>{ 
       void onDataRetrieved(ArrayList<T> listOfData); 
       void onDataRetrieveFail(ParseException e); 
  } 
}

Now, if you notice your method returns void. But requires an interface. So when you call this method you can set up the interface, and when it is called it will contain your data so for example to get headers:

 sessionHeaderFetch(new ParseIOListener<Date>() { 
     @Override 
     public void onDataRetrieved(ArrayList<Date> listOfData) { 
         //here you have your listOfData
     } 

     @Override 
     public void onDataRetrieveFail(ParseException e) { 
         //error. Log it out and handle it here
     } 
 });

这篇关于ParseQueryAdapter不取的物品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆