xujiaming 2016-8-19

完成云端数据查询、下载、显示的测试代码,测试成功
This commit is contained in:
TISSOT 2016-08-19 13:19:34 +08:00
parent d30395d631
commit ee6a0a39bd
20 changed files with 201 additions and 27 deletions

Binary file not shown.

Binary file not shown.

View File

@ -13,8 +13,16 @@ public final class R {
public static final class drawable { public static final class drawable {
public static final int ic_launcher=0x7f020000; public static final int ic_launcher=0x7f020000;
} }
public static final class id {
public static final int RelativeLayout1=0x7f060001;
public static final int lv_Personlist=0x7f060000;
public static final int tv_Paddress=0x7f060003;
public static final int tv_Pname=0x7f060002;
}
public static final class layout { public static final class layout {
public static final int activity_main=0x7f030000; public static final int activity_main=0x7f030000;
public static final int person_info=0x7f030001;
public static final int person_info_item=0x7f030002;
} }
public static final class string { public static final class string {
public static final int app_name=0x7f040000; public static final int app_name=0x7f040000;

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/lv_Personlist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:smoothScrollbar="true"
android:divider="@null">
</ListView>
</LinearLayout>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
>
<TextView
android:id="@+id/tv_Pname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="TextView1" />
<TextView
android:id="@+id/tv_Paddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/tv_Pname"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="TextView2" />
</RelativeLayout>

View File

@ -1,5 +1,6 @@
package com.example.bmob_test_pull; package com.example.bmob_test_pull;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import android.app.Activity; import android.app.Activity;
@ -7,6 +8,8 @@ import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.Toast; import android.widget.Toast;
import cn.bmob.v3.Bmob; import cn.bmob.v3.Bmob;
import cn.bmob.v3.BmobQuery; import cn.bmob.v3.BmobQuery;
@ -17,11 +20,28 @@ import cn.bmob.v3.listener.SaveListener;
import android.app.Activity; import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import com.example.bmob_test_pull.adapter.QueryAdapter;
import com.example.bmob_test_pull.model.Person; import com.example.bmob_test_pull.model.Person;
public class QueryActivity extends Activity{ public class QueryActivity extends Activity{
private ListView Persons;
private QueryAdapter mPersonListAdapter;
private List<Person> mPersonList;
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.person_info);
initView();
initData();
}
private void initData() {
// TODO Auto-generated method stub
BmobQuery<Person> query = new BmobQuery<Person>(); BmobQuery<Person> query = new BmobQuery<Person>();
query.addWhereEqualTo("address", "北京海淀"); query.addWhereEqualTo("address", "北京海淀");
@ -41,10 +61,29 @@ public class QueryActivity extends Activity{
// TODO Auto-generated method stub // TODO Auto-generated method stub
Log.i("bmob", "成功:" + "共计: " + arg0.size()); Log.i("bmob", "成功:" + "共计: " + arg0.size());
toast("bmobsuccess: " + "共计: " + arg0.size()); toast("bmobsuccess: " + "共计: " + arg0.size());
mPersonList = arg0;
mPersonListAdapter.refresh(mPersonList);
mPersonListAdapter.notifyDataSetChanged();
} }
}); });
} }
private void initView() {
// TODO Auto-generated method stub
Persons = (ListView) findViewById(R.id.lv_Personlist);
mPersonList = new ArrayList<Person>();
mPersonListAdapter = new QueryAdapter(this, mPersonList);
Persons.setAdapter(mPersonListAdapter);
//Persons.setOnItemClickListener(this);
}
private void toast(String toast) { private void toast(String toast) {
Toast.makeText(this, toast, Toast.LENGTH_SHORT).show(); Toast.makeText(this, toast, Toast.LENGTH_SHORT).show();
}; };

View File

@ -0,0 +1,10 @@
package com.example.bmob_test_pull.adapter;
import android.widget.TextView;
public class PersonHolder {
public TextView pName; //商品名称
public TextView pAddress; //商品单价
}

View File

@ -0,0 +1,74 @@
package com.example.bmob_test_pull.adapter;
import java.util.List;
import com.example.bmob_test_pull.model.Person;
import com.example.bmob_test_pull.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class QueryAdapter extends BaseAdapter{
private Context mContext;
private List<Person> mPersonList;
private LayoutInflater mInflater = null;
public QueryAdapter(Context context, List<Person> PersonList) {
mContext = context;
mPersonList = PersonList;
mInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return mPersonList.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return mPersonList.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
// 刷新列表中的数据
public void refresh(List<Person> list) {
mPersonList = list;
notifyDataSetChanged();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
PersonHolder personholder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.person_info_item, null);
personholder = new PersonHolder();
personholder.pName = (TextView) convertView
.findViewById(R.id.tv_Pname);
personholder.pAddress = (TextView) convertView
.findViewById(R.id.tv_Paddress);
convertView.setTag(personholder);
} else {
personholder = (PersonHolder) convertView.getTag();
}
personholder.pName.setText(mPersonList.get(position).getName());
personholder.pAddress.setText(mPersonList.get(position).getAddress());
return convertView;
}
}

View File

@ -2,3 +2,5 @@
2. Shop ——小组任务代码 2. Shop ——小组任务代码
3. 文档中王尚文的project和许家铭的project 3. 文档中王尚文的project和许家铭的project
19:41 2016/8/18 19:41 2016/8/18
4. bmob_test_pull——云端数据下载显示代码测试1——成功
13:16 2016/8/19

View File

@ -1,2 +0,0 @@
add SourceCode
8:20 2016/8/18