0
所以我已經遵循this關於創建自定義ParseQueryAdapter的教程,但由於某種原因,我的列表視圖沒有被填充。ParseQueryAdapter顯示空白列表
列表視圖活動
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listusers);
//Initialize the subclass of PQM
listViewAdapter = new ListViewAdapter(this);
//Initialize ListView and set view to listadapter
usersListView = (ListView) findViewById(R.id.usersListView);
usersListView.setAdapter(listViewAdapter);
ListViewAdapter
public class ListViewAdapter extends ParseQueryAdapter<ParseObject> {
public ListViewAdapter(Context context){
//Use Query factory to constuct a PQA that will not include the current user
super(context, new ParseQueryAdapter.QueryFactory<ParseObject>(){
public ParseQuery create(){
String currentUserId = ParseUser.getCurrentUser().getObjectId();
ParseQuery query = new ParseQuery("User");
query.whereNotEqualTo("objectId", currentUserId);
return query;
}
});
}
//Customise the layout by overriding getItemView
@Override
public View getItemView(ParseObject object, View v, ViewGroup parent){
if (v == null){
v = View.inflate(getContext(), R.layout.user_list_items, null);
}
super.getItemView(object, v, parent);
//Add the username textview
TextView userListItem = (TextView) v.findViewById(R.id.text1);
userListItem.setText(object.getString("username"));
//Add the status textview
TextView userListSubItem = (TextView) v.findViewById(R.id.userListSubItem);
userListSubItem.setText(object.get("status").toString());
return v;
}
}
activity_listusers XML文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/logout"
android:id="@+id/logoutButton"
android:gravity="center_vertical|center_horizontal"
android:layout_gravity="center_horizontal"
android:background="@color/dark_gray"
android:textSize="24sp"
android:padding="15dp"
android:textColor="@color/heartbeat_red" />
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
tools:context="com.sinch.messagingtutorialskeleton.ListUsersActivity"
android:background="#ffffff"
android:id="@+id/usersListView"
>
</ListView>
</LinearLayout>
User_List_Items XML文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/text1"
android:textColor="#a9a9a9"
android:padding="16dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="20sp">
</TextView>
<TextView
android:id="@+id/userListSubItem"
android:textColor="#a9a9a9"
android:padding="16dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/text1"
android:textSize="16sp">
</TextView>
</LinearLayout>
我對Android相對比較陌生,對Parse也很新,我不知道我哪裏出錯了,Parse可以正常工作,因爲我有一個預先使用Parse登錄的活動。
非常感謝,
編輯:所以我只是在Parse.com創建一個新的類和查詢,代替用戶和哪些工作,不知道如果你不能在用戶類,或者如果使用ParseQueryAdapter我試圖查詢它的方式是錯誤的?
看起來正確的給我。沒有logcat消息/錯誤? – cYrixmorten 2015-04-05 22:52:16
也許ParseQuery(「用戶」)應該是ParseQuery(「_ User」) – cYrixmorten 2015-04-05 22:57:00
@cYrixmorten是的,就是這樣!我沒有意識到,在使用ParseObject時,必須將User類稱爲_User,之前我只使用過ParseUser,但並不確定它可以在使用ParseObject的ParseQueryAdapter的所有教程中使用。謝謝 – 2015-04-05 23:08:54