gpt4 book ai didi

java - 自定义 ParseQueryAdapter 未填充 Android ListView

转载 作者:行者123 更新时间:2023-11-30 11:24:56 26 4
gpt4 key购买 nike

对于我正在制作的应用程序,我试图使用自定义 parsequeryadapter 子类使用从 parse.com 获得的数据填充 listView。基本上它只是在打开 Activity 时显示一个空白 Activity 。

适配器代码

package com.example.battlesim;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.parse.FindCallback;
import com.parse.ParseException;
import com.parse.ParseQuery;
import com.parse.ParseQueryAdapter;
import com.parse.ParseObject;

public class LeaderboardAdapter extends ParseQueryAdapter<ParseObject> {
public Context context;

public LeaderboardAdapter(Context c) {
super(c, new ParseQueryAdapter.QueryFactory<ParseObject>(){


public ParseQuery<ParseObject> create(){
// public final ArrayList<String> leadersName;
// public final ArrayList<Integer> leadersScore;
ParseQuery<ParseObject> queryL = ParseQuery.getQuery("Character");
queryL = queryL.whereNotEqualTo("name", null);
queryL = queryL.orderByDescending("level");
queryL.setLimit(10);
try {
queryL.find();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return queryL;

// queryL.findInBackground(new FindCallback<ParseObject>() {
// public void done(List<ParseObject> scoreList, ParseException e) {
// if (e == null) {
// for(int i = 0; i < 10; i++){
// leadersName.add(scoreList.get(i).getString("name"));
// leadersScore.add(scoreList.get(i).getInt("level"));
// }
// } else {
// Log.d("level", "Error: " + e.getMessage());
// }
// }

}
});
this.context = c;
}



public View getItemView(ParseObject o, View convertView, ViewGroup parent){
View vi = convertView;
if(convertView == null) vi = View.inflate(getContext(), R.layout.board, null);
super.getItemView(o, convertView, parent);
TextView name = (TextView) vi.findViewById(R.id.name);
TextView level = (TextView) vi.findViewById(R.id.level);

name.setText(o.getString("name"));
level.setText(o.getInt("level"));

return vi;
}

}

创建代码时的 Activity

LeaderboardAdapter adapter = new LeaderboardAdapter(this);
adapter.loadObjects();

ListView lv = (ListView) findViewById(R.id.listView1);
lv.setAdapter(adapter);

Board.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="TextView"
android:textSize="25dip"/>

<TextView
android:id="@+id/level"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="TextView"
android:textSize="25dip"/>

</RelativeLayout>

抱歉,如果我的格式不对或忘记包含任何内容。我是 StackExchange 的新手,对 Android 编程有些陌生

最佳答案

queryL.whereNotEqualTo("name", null); 替换为 queryL.whereExists("name");

关于java - 自定义 ParseQueryAdapter 未填充 Android ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20505816/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com