-1

I currently have my code to retrieve just one and i don't want them in a listview, just in two textviews.

code to retrieve one:

fRef = new Firebase("https://sw1ft13s-6b875.firebaseio.com/users/" + userID);
fRef.addChildEventListener(new ChildEventListener() {
    @Override
    public void onChildAdded(com.firebase.client.DataSnapshot dataSnapshot, String s) {
        String kills = dataSnapshot.getValue(String.class);
        textViewUserkills.setText(kills);    `

and it retrieves just one succuessfully but i have more than one textview to retrieve to in the layout file

the layout file is:

</FrameLayout>
    <LinearLayout
        android:id="@+id/linear"
        android:layout_below="@+id/head"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_alignParentStart="true">
        <customfonts.MyTextView
            android:layout_weight="1"
            android:id="@+id/textViewUserName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Godwin Jerome"
            android:textStyle="bold"
            android:textSize="25sp"
            android:textColorHint="#181737"
            android:textColor="#181737"
            android:background="#0000"
            android:padding="3dp"
            android:gravity="center" />

            <customfonts.MyTextView
                android:layout_weight="1"
                android:id="@+id/textViewUserkills"
                android:textSize="16sp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="---"
                android:textColorHint="#181737"
                android:textColor="#181737"
                android:maxLength="12"
                android:background="#0000"
                android:padding="2dp"
                android:gravity="center" />


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:paddingBottom="5dp">
            <customfonts.MyTextView
                android:layout_weight="1"
                android:id="@+id/textViewUserAddress"
                android:textSize="12sp"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:hint="Abeka Junction"
                android:textColorHint="#181737"
                android:textColor="#181737"
                android:padding="2dp"
                android:background="#0000"
                android:gravity="center" />
        </LinearLayout>
        <View
            android:layout_width="match_parent"
            android:layout_height="5dp"
            android:background="#dad8d8"/>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:background="#ffffff">
            <customfonts.MyTextView
                android:layout_weight="1"
                android:id="@+id/mail"
                android:textSize="16sp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Email"
                android:textColor="#a2a1b8"
                android:maxLength="12"
                android:background="#0000"
                android:padding="16dp"
                android:gravity="start"/>

            <customfonts.MyTextView
                android:id="@+id/textViewUserEmail"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#0000"
                android:gravity="end"
                android:hint="email@kalajob.com"
                android:padding="16dp"
                android:textColor="#181737"
                android:textColorHint="#1b193b"
                android:textSize="16sp" />
        </LinearLayout>
        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="#dad8d8"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:background="#ffffff">
            <customfonts.MyTextView
                android:layout_weight="1"
                android:id="@+id/pswrd"
                android:textSize="16sp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Phone Number"
                android:textColor="#a2a1b8"
                android:maxLength="12"
                android:background="#0000"
                android:padding="16dp"
                android:gravity="start" />

            <customfonts.MyTextView
                android:id="@+id/textViewPhoneNumber"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#0000"
                android:gravity="end"
                android:hint="054-321-9876"
                android:inputType="numberSigned"
                android:maxLength="12"
                android:padding="16dp"
                android:textColor="#181737"
                android:textColorHint="#1b193b"
                android:textSize="16sp" />
        </LinearLayout>
        <View
            android:layout_width="match_parent"
            android:layout_height="5dp"
            android:background="#dad8d8"/>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#ffffff"
            android:orientation="horizontal">

            <LinearLayout
                android:id="@+id/recm"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentStart="true"
                android:orientation="vertical"
                android:padding="8dp"
                android:paddingStart="8dp">

                <customfonts.MyTextView
                    android:id="@+id/sin"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:padding="1dp"
                    android:text="6"
                    android:textColor="#008cc9"
                    android:textSize="20sp" />

                <customfonts.MyTextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:padding="1dp"
                    android:text=" Recommends"
                    android:textColor="#181737"
                    android:textSize="15sp" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/feedb"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:orientation="vertical"
                android:paddingEnd="100dp"
                android:padding="8dp"
                android:paddingStart="8dp">

                <customfonts.MyTextView
                    android:id="@+id/sinn"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="1dp"
                    android:text="3"
                    android:textColor="#008cc9"
                    android:textSize="20sp" />

                <customfonts.MyTextView
                    android:layout_width="wrap_content"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:padding="1dp"
                    android:text=" Feedback"
                    android:textColor="#181737"
                    android:textSize="15sp" />
            </LinearLayout>
        </RelativeLayout>

my database structure is:

     sw1ft13s-6b875
       |---users
         |---26wr5p82UIhUkbv5VN00q9U0r3J2
                |---kills: "955"
                |---location: "Outside"
                |---name: "Godwin Nova"
                |---phoneNumber: "05477772586"    

Help? the other textview are name, address, phone number, rating. Super thanks in advance.

Kalaiyo5
  • 31
  • 10

2 Answers2

0

Use

fRef = new Firebase("https://sw1ft13s-6b875.firebaseio.com/users/" + userID);
fRef.addChildEventListener(new ChildEventListener() {
    @Override
    public void onChildAdded(com.firebase.client.DataSnapshot dataSnapshot, String s) {
        String kills = dataSnapshot.child("kills").getValue(String.class);
        textViewUserkills.setText(kills);
        String location=dataSnapshot.child("location").getValue(String.class);

and so on

Martin De Simone
  • 2,108
  • 3
  • 16
  • 30
  • thank you for your help... but, it doesnt retrieve back any data. unless i take out the " .child("kills") ". then it automatically retrieves the kills alone, ignoring the rest of the children (location, name, phonenumber). – Kalaiyo5 Jul 29 '17 at 10:39
  • Thanks for the concept ! – Kalaiyo5 Jul 29 '17 at 10:48
0

for this the best way is simply

What is the difference between ChildEventListener and ValueEventListener Firebase interfaces?

By changing the listener to valueEventListener(), retrieves the whole data for each value change.

fRef = new Firebase("https://sw1ft13s-6b875.firebaseio.com/users/" + userID);
fRef.addValueEventListener(new com.firebase.client.ValueEventListener() {
        @Override
        public void onDataChange(com.firebase.client.DataSnapshot dataSnapshot) {
            //String kills = dataSnapshot.getValue(String.class);
            String kills = dataSnapshot.child("kills").getValue(String.class);
            textViewUserkills.setText(kills);
            String location=dataSnapshot.child("location").getValue(String.class);
            textViewUserAddress.setText(location);

and so on! Thanks for the kick start from 'Martin De Simone'

Kalaiyo5
  • 31
  • 10