-1

I don't know in which part i made mistake. In UploadItemAdapter.class,uploadingDetails.getTitle() and uploadingDetails.getDiscription() both gives me null in my log cat. In android listView screen textView of item is also remains blank Screenshot .My Computer Screen. My code is mentioned below. UploadItemAdapter.java

package com.example.shiva.gconnection.extendedVersion;

import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.example.shiva.gconnection.R;
import com.example.shiva.gconnection.UploadingDetails;

import java.util.List;

/**
 * Created by shiva on 3/3/18.
 */

public class UploadItemAdapter extends ArrayAdapter<UploadingDetails>{
    public UploadItemAdapter( Context context, int resource, List<UploadingDetails> objects) {
        super(context, resource, objects);
    }

    @Override
    public View getView(int position ,View convertView,ViewGroup parent) {
        if (convertView == null) {
            convertView = ((FragmentActivity) getContext()).getLayoutInflater().inflate(R.layout.uploaded_material_child, parent, false);
        }
        TextView titalTV = (TextView) convertView.findViewById(R.id.title_item_upload_material);
        TextView discriptionTV= (TextView) convertView.findViewById(R.id.discription_item_upload_material);

        UploadingDetails uploadingDetails = getItem(position);
        titalTV.setText(uploadingDetails.getTitle());
        discriptionTV.setText(uploadingDetails.getDiscription());
        Log.v("abcd",uploadingDetails.getTitle() +" "+uploadingDetails.getDiscription());
        return convertView;
    }
}

uploaded_material.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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="10dp"
    android:orientation="vertical">

    <ListView
        android:id="@+id/lv_upload_item"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:transcriptMode="alwaysScroll"
        tools:listitem="@layout/uploaded_material_child" />
</LinearLayout>

Uploaded_material_child.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="wrap_content">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Title"
        android:id="@+id/title_item_upload_material"
        android:textSize="20dp"
        android:textColor="@android:color/black"
        android:layout_margin="5dp"/>
    <TextView
        android:layout_margin="5dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Discription"
        android:textColor="@android:color/black"
        android:id="@+id/discription_item_upload_material"
        android:textSize="16dp" />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="UploadedBy"
        android:id="@+id/uploaded_by"
        android:textSize="16dp"
        android:textColor="@android:color/black"
        android:layout_margin="5dp"/>
</LinearLayout>

FragmentLastView.java

package com.example.shiva.gconnection.extendedVersion;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.example.shiva.gconnection.R;
import com.example.shiva.gconnection.UploadingDetails;
import com.google.firebase.database.ChildEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

import java.util.ArrayList;

public class FragmentLastView extends Fragment {
    private FirebaseDatabase mdatabase;
    private DatabaseReference mdbRef;
    private ListView mItemLV;
    private ChildEventListener childEventListener;
    private ArrayAdapter mUploadItemAdapter;

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view= inflater.inflate(R.layout.uploaded_material,container,false);
        mdatabase = FirebaseDatabase.getInstance();
        mdbRef = mdatabase.getReference("College");
        return view;
    }

    @Override
    public void onViewCreated(View view,Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        final String subjectName = getArguments().getString("SubjectName");
        final String branchname = getArguments().getString("BranchName");
        final String class1Name = getArguments().getString("Class1Name");
        final String className = getArguments().getString("ClassName");

        final ArrayList<UploadingDetails> uploadingDetails = new ArrayList<>();
        mItemLV= (ListView)view.findViewById(R.id.lv_upload_item);

        mUploadItemAdapter = new UploadItemAdapter(view.getContext(),R.layout.uploaded_material_child,uploadingDetails);
        mItemLV.setAdapter(mUploadItemAdapter);

        childEventListener = new ChildEventListener() {
            @Override
            public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                UploadingDetails updetails = dataSnapshot.getValue(UploadingDetails.class);
                uploadingDetails.add(updetails);
                mUploadItemAdapter.notifyDataSetChanged();
            }
            @Override
            public void onChildChanged(DataSnapshot dataSnapshot, String s) {}
            @Override
            public void onChildRemoved(DataSnapshot dataSnapshot) {}
            @Override
            public void onChildMoved(DataSnapshot dataSnapshot, String s) {}
            @Override
            public void onCancelled(DatabaseError databaseError) {}
        };
        mdbRef.child(branchname).child(subjectName).child(className).child(class1Name).addChildEventListener(childEventListener);


    }
}

UploadingDetails.java

package com.example.shiva.gconnection;

    public class UploadingDetails {
        private String mTitle;
        private String mDiscription;
        private String mArrayUri;

        public UploadingDetails(){
        }

        public UploadingDetails(String title, String discription,String arrayUri){
            this.mTitle= title;
            this.mDiscription=discription;
            this.mArrayUri=arrayUri;

        }

        public String getTitle(){
            return this.mTitle;
        }

        public String getDiscription(){
            return this.mDiscription;
        }

        public String getArrayUri(){return this.mArrayUri;}
    }
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
Shiva.AK
  • 29
  • 8
  • Code dumps are generally unhelpful. Please post a succinct example that demonstrates your issue. – user3483203 Mar 04 '18 at 06:07
  • I don't understand what you are asking for .....??? – Shiva.AK Mar 04 '18 at 06:09
  • You should not just dump large amounts of code in your question. Post the minimum amount of code needed to reproduce the problem you are having. – user3483203 Mar 04 '18 at 06:09
  • onChildAdded is there data coming accurately ?? – Santanu Sur Mar 04 '18 at 06:12
  • I think everyThing i posted will need for reproduce the problem..... i am beginner in android. I can't find in which part i have problem. even my logCat is not showing me error. my application is not crashing. i stuck with part...... i tried a lot to figure problem. please check above sceenshot of my android and pc screen perhaps it will help you for answering. – Shiva.AK Mar 04 '18 at 06:17
  • yes sir dataSnapshot.toString() in logCat gives me the object. thats ok... – Shiva.AK Mar 04 '18 at 06:19
  • may be you are right sir... there is problem with onChildAdded....data is comming accurately but its not storing in the variable which is diclared as class i tried following code which gives error ... mItemLV.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView> parent, View view, int position, long id) { UploadingDetails upd = uploadingDetails.get(position); Log.v("abcd",upd.getTitle()); } }); – Shiva.AK Mar 04 '18 at 06:33
  • Please use [`FirebaseListAdapter`](https://firebaseui.com/docs/android/com/firebase/ui/FirebaseListAdapter.html) instead of `ArrayAdapter` in `UploadItemAdapter`. Firebase SDK automatically handles data change. Take advantage of that. – Belladonna Mar 04 '18 at 06:54
  • when i tried `Log.v("abcd", String.valueOf(uploadingDetails.size()));` in FragmentLastView.java gives me zero value each time whether there is data or not. – Shiva.AK Mar 04 '18 at 12:40
  • when i put `Log.v("abcd", String.valueOf(uploadingDetails.size()));` inside onChildadded Method it gives me the exact size of uploadingDetails ArrayList – Shiva.AK Mar 04 '18 at 13:00

2 Answers2

0

The name of the fields in your model class must much to the name of the data on witch your want retrieve in firebase data reference node

-1

I don't understand how it worked but when i changed following code problem was solved UploadindDetils.java

package com.example.shiva.gconnection;

public class UploadingDetails {
    private String mTitle;
    private String mDiscription;
    private String mArrayUri;

    public UploadingDetails() {
    }

    public UploadingDetails(String title, String discription, String arrayUri) {
        this.mTitle = title;
        this.mDiscription = discription;
        this.mArrayUri = arrayUri;

    }

    public String getTitle() {
        return this.mTitle;
    }

    public void setTitle(String title) {
        this. mTitle = title;
    }

    public void setDiscription(String discription) {
        this.mDiscription = discription;
    }

    public void setArrayUri(String arrayUri) {
        this.mArrayUri = arrayUri;
    }

    public String getDiscription() {
        return this.mDiscription;
    }

    public String getArrayUri() {
        return this.mArrayUri;
    }
}
Shiva.AK
  • 29
  • 8