我正在开发一个社交网络应用程序,我需要一个活动,在parse.com中显示我的用户表中的所有数据。我试过这段代码,但结果总是一个空的空白屏幕。 这是活动的代码
public class UsersList extends Activity {
private ParseQueryAdapter<Userr> mainAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_users_list);
ListView listhope = (ListView) findViewById(R.id.userlistlist);
mainAdapter = new MyParseUserListAdaptor(this, Userr.class);
listhope.setAdapter(mainAdapter);
mainAdapter.loadObjects();
}
[...]
}
这是listview的布局文件
<LinearLayout
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/usslist">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/userlistlist"
/>
</LinearLayout>
这是我创建的自定义适配器
public class MyParseUserListAdaptor extends ParseQueryAdapter<Userr> {
public MyParseUserListAdaptor(Context context,
Class<?extends ParseUser> clazz) {
super(context, clazz);
// TODO Auto-generated constructor stub
}
@Override
public View getItemView(Userr userme, View v, ViewGroup parent) {
if (v == null) {
v = View.inflate(getContext(), R.layout.usertem, null);
}
super.getItemView(userme, v, parent);
ParseImageView userlistpic = (ParseImageView) v.findViewById(R.id.imageView);
TextView userListName = (TextView) v.findViewById(R.id.userName);
TextView userListEmail = (TextView) v.findViewById(R.id.userEmail);
userlistpic.setParseFile(userme.getPhotoFile());
userListName.setText(userme.getUser_Name(ParseUser.getCurrentUser()));
userListEmail.setText(userme.getUser_Email(ParseUser.getCurrentUser()));
userlistpic.loadInBackground();
return v;
}
}
这是我的Userr类
@ParseClassName("Userr")
public class Userr extends ParseUser {
public Userr() {
// A default constructor is required.
}
最后这是listview项目布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/userittem">
<com.parse.ParseImageView
android:id="@+id/imageView"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Mohamed Sherif"
android:id="@+id/userName"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/imageView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="mohamedsherifhazem@gmail.com"
android:id="@+id/userEmail"
android:layout_below="@+id/userName"
android:layout_toEndOf="@+id/imageView" />
</RelativeLayout>
代码:
public String getUser_Name(ParseUser user) {
String name = user.get("name").toString();
if (name != null)
return name;
else return "Anonymous";
}
public String getUser_Email(ParseUser user) {
String email = user.getEmail();
if (email != null)
return email;
else return "Anonymous";
}
public ParseFile getPhotoFile() {
return getParseFile("profile_picture");
}
}