LeanCloud php 怎么实现模糊查询
发布网友
发布时间:2022-04-06 04:26
我来回答
共1个回答
热心网友
时间:2022-04-06 05:55
实现了基本的查询,将查到的数据添加到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);
}
});
}
}