首页 > 代码库 > LeanCloud学习笔记(1)
LeanCloud学习笔记(1)
实现了基本的查询,将查到的数据添加到ListView中。
package com.itfanr.internalweb; import java.util.ArrayList; import java.util.List; import com.itfanr.internalweb.R; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.widget.ArrayAdapter; import android.widget.ListView; import com.avos.avoscloud.AVException; import com.avos.avoscloud.AVOSCloud; import com.avos.avoscloud.AVAnalytics; import com.avos.avoscloud.AVObject; import com.avos.avoscloud.AVQuery; import com.avos.avoscloud.FindCallback; public class MainActivity extends Activity { private ListView mListView; private ArrayList<String> dataList = new ArrayList<String>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); AVAnalytics.trackAppOpened(getIntent()); setContentView(R.layout.activity_main); mListView = (ListView) findViewById(R.id.post_list); getData(); } private void getData() { List<String> data = new ArrayList<String>(); AVQuery<AVObject> query = new AVQuery<AVObject>("Post"); query.whereLessThanOrEqualTo("postId", 10); query.findInBackground(new FindCallback<AVObject>() { @Override public void done(List<AVObject> arg0, AVException arg1) { Log.d("查到了", arg0.size() + ""); int resultSize = arg0.size(); for (int i = 0; i < resultSize; i++) { MainActivity.this.dataList.add(arg0.get(i).getString( "postTitle")); } ArrayAdapter<String> myArrayAdapter = new ArrayAdapter<String>( MainActivity.this, android.R.layout.simple_list_item_1, dataList); mListView.setAdapter(myArrayAdapter); } }); } }
LeanCloud学习笔记(1)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。