列表视图未显示来自无尽数据库的数据

时间:2020-02-12 03:02:23

标签: java android-studio arraylist backendless

我正在android studio中构建联系人应用程序。 其他所有事情,例如登录,注册都在应用程序中运行。 我没有从android studio的listview中的后端数据库获取数据。 但我的活动正在运行,并且崩溃的原因是应用程序内。有人可以帮忙吗?

view_contacts.java

package com.example.testapp;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

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

import java.util.List;

public class view_contact extends AppCompatActivity {

    ListView lvlist;
    ContactAdapter adapter;
    TextView contacts;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_contact);

        contacts=findViewById(R.id.tvcontacts);
        lvlist=findViewById(R.id.list_view);

        String whereClause="userEmail = '" + TestApplication.user.getEmail() +"'";
        DataQueryBuilder queryBuilder=DataQueryBuilder.create();
        queryBuilder.setWhereClause(whereClause);
        queryBuilder.setGroupBy("name");

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

                TestApplication.contacts = response;
                adapter=new ContactAdapter(view_contact.this,TestApplication.contacts);
                lvlist.setAdapter(adapter);

            }

            @Override
            public void handleFault(BackendlessFault fault) {
                Toast.makeText(view_contact.this, "Error : "+fault.getMessage(), Toast.LENGTH_SHORT).show();
            }
        });



    }
}

ContactsAdapter.java

package com.example.testapp;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.List;

public class ContactAdapter extends ArrayAdapter<Contact> {


    private Context context;
    private List<Contact> contacts;

    public ContactAdapter(@NonNull Context context, List<Contact> contacts) {
        super(context,R.layout.row_layout);
        this.context = context;
        this.contacts = contacts;
    }

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

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

        TextView tvchar=convertView.findViewById(R.id.tvchar);
        TextView tvname=convertView.findViewById(R.id.tvname);
        TextView tvmail=convertView.findViewById(R.id.tvmail);

        tvchar.setText(contacts.get(position).getName().toUpperCase().charAt(0));
        tvname.setText(contacts.get(position).getName());
        tvmail.setText(contacts.get(position).getEmail());

        return convertView;

    }
}

TestApplication.java

// I have set up my backendless database code above and my list is declared public below
public static List<Contact> contacts;

logcat:-

2020-02-12 18:27:55.078 13205-13229/com.example.testapp D/EGL_emulation: eglMakeCurrent: 0xa1107260: ver 2 0 (tinfo 0xa901b4f0)
2020-02-12 18:27:58.118 13205-13229/com.example.testapp D/EGL_emulation: eglMakeCurrent: 0xa1107260: ver 2 0 (tinfo 0xa901b4f0)
2020-02-12 18:27:58.138 13205-13229/com.example.testapp D/EGL_emulation: eglMakeCurrent: 0xa1107260: ver 2 0 (tinfo 0xa901b4f0)
2020-02-12 18:27:58.152 13205-13229/com.example.testapp D/EGL_emulation: eglMakeCurrent: 0xa1107260: ver 2 0 (tinfo 0xa901b4f0)
2020-02-12 18:27:58.170 13205-13229/com.example.testapp I/chatty: uid=10090(com.example.testapp) RenderThread identical 1 line
2020-02-12 18:27:58.178 13205-13229/com.example.testapp D/EGL_emulation: eglMakeCurrent: 0xa1107260: ver 2 0 (tinfo 0xa901b4f0)
2020-02-12 18:27:59.649 13205-13229/com.example.testapp D/EGL_emulation: eglMakeCurrent: 0xa1107260: ver 2 0 (tinfo 0xa901b4f0)

1 个答案:

答案 0 :(得分:0)

您的应用程序崩溃了吗?如果是这样,请提供崩溃日志。

您是否从服务器收到联系人列表?确保Contact表中有与whereClause相匹配的条目。