为什么我的ListView没有显示任何内容?

时间:2017-09-13 10:46:01

标签: android listview backendless

//我在android中有一个自定义ListView并设置了一个适配器。我的问题是//列表视图没有显示任何内容,无论适配器如何,请注意我从Backendless服务中检索信息。请帮忙

//适配器代码

package za.ac.cut.afinal;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import android.widget.Toast;

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


/**
* Created by User on 2017/09/12.
*/

public class StudentAdapter extends ArrayAdapter<Student_Class> {

private final Context context;
private final List<Student_Class> values;
TextView tvName, tvSurname,tvGender,tvRace;

public  StudentAdapter(Context context, List<Student_Class> list)
{
super(context,R.layout.custom_student_row_layout);
this.context = context;
this.values = list;

}

@Override
public long getItemId(int position) {
return super.getItemId(position);
}

@Nullable
@Override
public Student_Class getItem(int position) {
return values.get(position);
}

@Override
public int getCount() {
return  values == null ? 0 : values.size();
}

@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {

View rowView = convertView;


LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(R.layout.custom_student_row_layout,parent,false);

 tvName = (TextView) rowView.findViewById(R.id.customSNmae);
 tvSurname = (TextView) rowView.findViewById(R.id.tv_customSSurname);
 tvGender = (TextView) rowView.findViewById(R.id.customSGender);
 tvRace = (TextView) rowView.findViewById(R.id.customSRace);

Toast.makeText(context, "help" + values.get(position).getL_fname(), Toast.LENGTH_SHORT).show();
Toast.makeText(context, "help2" + values.get(position).getL_lname(), Toast.LENGTH_SHORT).show();
Toast.makeText(context, "help3" + values.get(position).getL_gender(), Toast.LENGTH_SHORT).show();
Toast.makeText(context, "help4" + values.get(position).getL_race(), Toast.LENGTH_SHORT).show();

tvName.setText(values.get(position).getL_fname());
tvSurname.setText(values.get(position).getL_lname());
tvGender.setText(values.get(position).getL_gender());
tvRace.setText(values.get(position).getL_race());

return rowView ;
}
}

//类Listview     包za.ac.cut.afinal;

import android.content.Context;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.Adapter;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.backendless.Backendless;
import com.backendless.async.callback.AsyncCallback;
import com.backendless.exceptions.BackendlessFault;
import com.backendless.persistence.BackendlessDataQuery;
import com.backendless.persistence.DataQueryBuilder;
import com.backendless.persistence.QueryOptions;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import weborb.client.ant.wdm.View;

public class Student_List extends AppCompatActivity {

ListView lv;
List<Student_Class> StudentsList;
Student_Class student ;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_student_list);
lv = (ListView)findViewById(R.id.lvStudentDetails1);

retrieveStudent();
}

@Override
protected void onResume() {
super.onResume();
retrieveStudent();
}

private void retrieveStudent()
{

//     progressBar.setVisibility(android.view.View.VISIBLE);

if(StudentsList != null)
{
StudentsList.clear();
}
String whereClause = "u_Name = '12'";
DataQueryBuilder queryBuilder = DataQueryBuilder.create();
queryBuilder.setWhereClause(whereClause);
queryBuilder.setPageSize(100);
queryBuilder.setSortBy("l_fname");

Backendless.Persistence.of(Student_Class.class).find(queryBuilder, new AsyncCallback<List<Student_Class>>() {
@Override
public void handleResponse(List<Student_Class> response) {

    for (int x = 0; x < response.size(); x++) {
        student = new Student_Class(response.get(x).getL_IDNo(), response.get(x).getL_fname(), response.get(x).getL_lname(),
                response.get(x).getL_className(), response.get(x).getL_gender(),
                response.get(x).getL_race(), response.get(x).getL_DOB(),
                response.get(x).getL_classLang(), response.get(x).getL_fullOrhalfday(),
                response.get(x).getL_DOE(), response.get(x).getL_address(),
                response.get(x).getL_mGardian(), response.get(x).getL_fGardian(),
                response.get(x).getL_mGardianEmail(), response.get(x).getL_fGardianEmail(),
                response.get(x).getL_mGardianCell(), response.get(x).getL_fGardianCell(),
                response.get(x).getL_doc(),
                response.get(x).getL_doctCell(), response.get(x).getL_medicalAid(),
                response.get(x).getL_medicalAidPlan(), response.get(x).getL_medicalAidPlanNo(),
                response.get(x).getL_allergies(), response.get(x).getL_tuckshopBalance()
                , response.get(x).getCreated(), response.get(x).getUpdated(),
                response.get(x).getObjectID());

    }
    StudentsList.add(student);
    if (StudentsList != null) {

        StudentAdapter adapter = new StudentAdapter(Student_List.this,StudentsList);
        lv.setAdapter(adapter);
        Helper_Class.ShowToast(Student_List.this,"WTF");
    }else {
//                        tv_emptyList.setVisibility(View.VISIBLE);
        Helper_Class.ShowToast(Student_List.this,"No Learners enrolled for this class");
    }

}
@Override
public void handleFault(BackendlessFault fault) {

}
});
}
}

//学生班

package za.ac.cut.afinal;

import java.util.Date;

/**
* Created by User on 2017/09/10.
*/

public class Student_Class {

private Date created;
private Date updated;
private String objectID;




private String l_IDNo;
private String l_fname;
private String l_lname;
private String l_className;
private String l_gender;
private String l_race;
private String l_DOB;
private String l_classLang;
private String l_fullOrhalfday;
private String l_DOE;
private String l_address;
private String l_mGardian;
private String l_fGardian;
private String l_mGardianEmail;
private String l_fGardianEmail;
private String l_mGardianCell;
private String l_fGardianCell;
private String l_doc;
private String l_doctCell;
private String l_medicalAid;
private String l_medicalAidPlan;
private String l_medicalAidPlanNo;
private String l_allergies;
private String l_tuckshopBalance;

public Student_Class(String l_fname, String l_lname, String l_gender, String l_race) {
this.l_fname = l_fname;
this.l_lname = l_lname;
this.l_gender = l_gender;
this.l_race = l_race;
}

public Student_Class() {
l_IDNo = null;
l_fname = null;
l_lname = null;
l_className = null;
l_gender = null;
l_race = null;
l_DOB = null;
l_classLang = null;
l_fullOrhalfday = null;
l_DOE = null;
l_address = null;
l_mGardian = null;
l_fGardian = null;
l_mGardianEmail = null;
l_fGardianEmail = null;
l_mGardianCell = null;
l_fGardianCell = null;
l_doc = null;
l_doctCell = null;
l_medicalAid = null;
l_medicalAidPlan = null;
l_medicalAidPlanNo = null;
l_allergies = null;
l_tuckshopBalance = null;
created = null;
updated = null;
objectID = null;

}

public Student_Class(String l_IDNo, String l_fname, String l_lname, String l_className, String l_gender, String l_race, String l_DOB, String l_classLang, String l_fullOrhalfday, String l_DOE, String l_address, String l_mGardian, String l_fGardian, String l_mGardianEmail, String l_fGardianEmail, String l_mGardianCell, String l_fGardianCell, String l_doc, String l_doctCell, String l_medicalAid, String l_medicalAidPlan, String l_medicalAidPlanNo, String l_allergies, String l_tuckshopBalance,Date created, Date updated, String objectID) {
this.created = created;
this.updated = updated;
this.objectID = objectID;
this.l_IDNo = l_IDNo;
this.l_fname = l_fname;
this.l_lname = l_lname;
this.l_className = l_className;
this.l_gender = l_gender;
this.l_race = l_race;
this.l_DOB = l_DOB;
this.l_classLang = l_classLang;
this.l_fullOrhalfday = l_fullOrhalfday;
this.l_DOE = l_DOE;
this.l_address = l_address;
this.l_mGardian = l_mGardian;
this.l_fGardian = l_fGardian;
this.l_mGardianEmail = l_mGardianEmail;
this.l_fGardianEmail = l_fGardianEmail;
this.l_mGardianCell = l_mGardianCell;
this.l_fGardianCell = l_fGardianCell;
this.l_doc = l_doc;
this.l_doctCell = l_doctCell;
this.l_medicalAid = l_medicalAid;
this.l_medicalAidPlan = l_medicalAidPlan;
this.l_medicalAidPlanNo = l_medicalAidPlanNo;
this.l_allergies = l_allergies;
this.l_tuckshopBalance = l_tuckshopBalance;
}

public Date getCreated() {
return created;
}

public void setCreated(Date created) {
this.created = created;
}

public Date getUpdated() {
return updated;
}

public void setUpdated(Date updated) {
this.updated = updated;
}

public String getObjectID() {
return objectID;
}

public void setObjectID(String objectID) {
this.objectID = objectID;
}


public String getL_IDNo() {
return l_IDNo;
}

public void setL_IDNo(String l_IDNo) {
this.l_IDNo = l_IDNo;
}

public String getL_fname() {
return l_fname;
}

public void setL_fname(String l_fname) {
this.l_fname = l_fname;
}

public String getL_lname() {
return l_lname;
}

public void setL_lname(String l_lname) {
this.l_lname = l_lname;
}

public String getL_className() {
return l_className;
}

public void setL_className(String l_className) {
this.l_className = l_className;
}

public String getL_gender() {
return l_gender;
}

public void setL_gender(String l_gender) {
this.l_gender = l_gender;
}

public String getL_race() {
return l_race;
}

public void setL_race(String l_race) {
this.l_race = l_race;
}

public String getL_DOB() {
return l_DOB;
}

public void setL_DOB(String l_DOB) {
this.l_DOB = l_DOB;
}

public String getL_classLang() {
return l_classLang;
}

public void setL_classLang(String l_classLang) {
this.l_classLang = l_classLang;
}

public String getL_fullOrhalfday() {
return l_fullOrhalfday;
}

public void setL_fullOrhalfday(String l_fullOrhalfday) {
this.l_fullOrhalfday = l_fullOrhalfday;
}

public String getL_DOE() {
return l_DOE;
}

public void setL_DOE(String l_DOE) {
this.l_DOE = l_DOE;
}

public String getL_address() {
return l_address;
}

public void setL_address(String l_address) {
this.l_address = l_address;
}

public String getL_mGardian() {
return l_mGardian;
}

public void setL_mGardian(String l_mGardian) {
this.l_mGardian = l_mGardian;
}

public String getL_fGardian() {
return l_fGardian;
}

public void setL_fGardian(String l_fGardian) {
this.l_fGardian = l_fGardian;
}

public String getL_mGardianEmail() {
return l_mGardianEmail;
}

public void setL_mGardianEmail(String l_mGardianEmail) {
this.l_mGardianEmail = l_mGardianEmail;
}

public String getL_fGardianEmail() {
return l_fGardianEmail;
}

public void setL_fGardianEmail(String l_fGardianEmail) {
this.l_fGardianEmail = l_fGardianEmail;
}

public String getL_mGardianCell() {
return l_mGardianCell;
}

public void setL_mGardianCell(String l_mGardianCell) {
this.l_mGardianCell = l_mGardianCell;
}

public String getL_fGardianCell() {
return l_fGardianCell;
}

public void setL_fGardianCell(String l_fGardianCell) {
this.l_fGardianCell = l_fGardianCell;
}

public String getL_doc() {
return l_doc;
}

public void setL_doc(String l_doc) {
this.l_doc = l_doc;
}

public String getL_doctCell() {
return l_doctCell;
}

public void setL_doctCell(String l_doctCell) {
this.l_doctCell = l_doctCell;
}

public String getL_medicalAid() {
return l_medicalAid;
}

public void setL_medicalAid(String l_medicalAid) {
this.l_medicalAid = l_medicalAid;
}

public String getL_medicalAidPlan() {
return l_medicalAidPlan;
}

public void setL_medicalAidPlan(String l_medicalAidPlan) {
this.l_medicalAidPlan = l_medicalAidPlan;
}

public String getL_medicalAidPlanNo() {
return l_medicalAidPlanNo;
}

public void setL_medicalAidPlanNo(String l_medicalAidPlanNo) {
this.l_medicalAidPlanNo = l_medicalAidPlanNo;
}

public String getL_allergies() {
return l_allergies;
}

public void setL_allergies(String l_allergies) {
this.l_allergies = l_allergies;
}

public String getL_tuckshopBalance() {
return l_tuckshopBalance;
}

public void setL_tuckshopBalance(String l_tuckshopBalance) {
this.l_tuckshopBalance = l_tuckshopBalance;
}
}

3 个答案:

答案 0 :(得分:0)

从后端检索数据后

设置adapter.notifyDataSetChanged();。 信息数据变量必须是相同的参考地址,我的意思是在检索数据后不再使用malloc等。

答案 1 :(得分:0)

有一些错误:

1)StudentsList永远不会被玷污(永远为空)

2)StudentsList.add(student);无效,因为SutendList为空

3)StudentsList.add(student);应该在for循环中调用,你为什么要在外面调用它?

答案 2 :(得分:0)

一切都运转正常,我错误地输入了错误的字符串&#34; String whereClause =&#34; u_Name =&#39; 12&#39;&#34;;&#34;

36小时问题是一个字符串!