Display the node data in a ListView Firebase

0

I'm learning Android and I'm trying to display data from the Characteristics node in a ListView , however, it's not displaying anything in ListView . Anyone who can help will thank you.

char_list.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">
    <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:id="@+id/textViewSinal"
                android:layout_width="448dp"
                android:layout_height="wrap_content"
                android:paddingLeft="8dp"
                android:paddingRight="8dp"
                android:paddingTop="18sp"
                android:text="Sinal"
                android:textSize="18dp" />

    </LinearLayout>
</RelativeLayout>

activity_acty_caracte.xml

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

            <ListView
                android:id="@+id/listViewCaracteristica"
                android:layout_width="329dp"
                android:layout_height="wrap_content"
                android:divider="@color/colorPrimary"
                android:dividerHeight="1dp"/>

</RelativeLayout>

Character Adapter

public class CaracteristicasAdapter extends ArrayAdapter<Caracteristica>{

    private ArrayList<Caracteristica> arrayList;
    private Context context;

    public CaracteristicasAdapter(@NonNull Context c, @NonNull ArrayList<Caracteristica> objects) {
        super(c, 0, objects);
        this.context = c;
        this.arrayList = objects;
    }
    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        View view = null;

        if (arrayList !=null){
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(R.layout.lista_caracteristicas, parent, false);

            TextView textViewSinal = (TextView) view.findViewById(R.id.textViewSinal);

            Caracteristica caracteristica2 = arrayList.get(position);
            textViewSinal.setText(caracteristica2.getSinal());


        }
        return view;
    }
}

ActyCaracte

public class ActyCaracte extends Activity {
private ListView listView;
private ArrayAdapter adapter;
private ArrayList<Caracteristica> arrayList;
private DatabaseReference firebase;
private ValueEventListener valueEventListenerCaracteristica;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_acty_caracte);
    arrayList = new ArrayList<>();
    listView = (ListView) findViewById(R.id.listViewCaracteristica);
    adapter = new CaracteristicasAdapter(this, arrayList);
    listView.setAdapter(adapter);
    firebase = ConfiguracaoFirebase.getFirebase().child("Caracteristica");
    valueEventListenerCaracteristica = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            arrayList.clear();
            for (DataSnapshot dados : dataSnapshot.getChildren()) {
                Caracteristica caracteristicaNovo = dados.getValue(Caracteristica.class);
                arrayList.add(caracteristicaNovo);
            }
            adapter.notifyDataSetChanged();
        }
        @Override
        public void onCancelled(DatabaseError databaseError) {

        }

    };
}
    @Override
    protected void onStart() {
        super.onStart();
        firebase.addValueEventListener(valueEventListenerCaracteristica);
    }

    @Override
    protected void onStop() {
        super.onStop();
        firebase.removeEventListener(valueEventListenerCaracteristica);
    }

}
    
asked by anonymous 20.05.2018 / 19:28

0 answers