Bonjour tout le monde, svp j'arrive a inserer des donnees dans firebase mais quand je tente de les afficher dans mon fragment liste_offres.xml, mon apli ne repond plus. voic le code d'affichage
ListeOffres.java
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package com.codeeaters.taffer;
 
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
 
import com.google.android.gms.common.ConnectionResult;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
 
/**
 * Created by pondikpa on 12/01/17.
 */
 
public class ListeOffres  extends android.support.v4.app.Fragment {
 
 
 
    public static class OffreViewHolder extends RecyclerView.ViewHolder{
        public TextView offreType;
        public TextView offreDomaine;
        public TextView offrePoste;
        public TextView offreEtude;
        public TextView offreContact;
        public TextView offreSalaire;
        public TextView offreAdresse;
        public TextView offreDescription;
 
        public OffreViewHolder(View v){
            super(v);
            offreType = (TextView)itemView.findViewById(R.id.typetxt);
            offreDomaine = (TextView)itemView.findViewById(R.id.domainetxt);
            offreEtude = (TextView)itemView.findViewById(R.id.scolairetxt);
            offrePoste = (TextView)itemView.findViewById(R.id.postetxt);
            offreContact = (TextView)itemView.findViewById(R.id.contacttxt);
            offreSalaire = (TextView)itemView.findViewById(R.id.salairetxt);
            offreAdresse = (TextView)itemView.findViewById(R.id.adressetxt);
            offreDescription = (TextView)itemView.findViewById(R.id.descriptiontxt);
 
        }
 
    }
    private static final String OFFRES = "offres";
    private static final String TAG = "ListeOffres";
    private  RecyclerView mOffreRecyclerView;
    private LinearLayoutManager mLinearLayoutManager;
    private DatabaseReference mFirebaseDatabaseReference;
    private  FirebaseRecyclerAdapter<OffresDAO, OffreViewHolder> mFirebaseAdapter;
 
 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        View rootView= inflater .inflate(R.layout.liste_offres, container, false);
        mOffreRecyclerView =(RecyclerView)rootView.findViewById(R.id.offreRecyclerView);
        Log.i(TAG, "onConnectionFailed: hein");
        mLinearLayoutManager = new LinearLayoutManager(this.getActivity());
        mLinearLayoutManager.setStackFromEnd(true);
        mFirebaseDatabaseReference = FirebaseDatabase.getInstance().getReference();
        mFirebaseAdapter = new FirebaseRecyclerAdapter<OffresDAO, OffreViewHolder>(
            OffresDAO.class,
            R.layout.offre,
            OffreViewHolder.class,
            mFirebaseDatabaseReference.child(OFFRES)){
                @Override
                protected void populateViewHolder(OffreViewHolder viewHolder, OffresDAO model, int position){
                    viewHolder.offreType.setText(model.getTypechoi());
                    viewHolder.offreDomaine.setText(model.getDomainechoi());
                    viewHolder.offreEtude.setText(model.getEtudechoi());
                    viewHolder.offrePoste.setText(model.getPostechoi());
                    viewHolder.offreSalaire.setText(model.getSalairechoi());
                    viewHolder.offreContact.setText(model.getContactchoi());
                    viewHolder.offreAdresse.setText(model.getAdressechoi());
                    viewHolder.offreDescription.setText(model.getDescriptionchoix());
                }
 
            };
            mFirebaseAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver(){
                @Override
                public void onItemRangeInserted(int positionStart, int itemCount){
                    super.onItemRangeInserted(positionStart,itemCount);
                    int roomCount = mFirebaseAdapter.getItemCount();
                    int lastVisiblePosition = mLinearLayoutManager.findLastCompletelyVisibleItemPosition();
                    if (lastVisiblePosition == -1 || (positionStart >= (roomCount -1) && lastVisiblePosition == (positionStart -1))){
                        mOffreRecyclerView.scrollToPosition(positionStart);
                    }
                }
            });
            mOffreRecyclerView.setLayoutManager(mLinearLayoutManager);
            mOffreRecyclerView.setAdapter(mFirebaseAdapter);
 
 
        return  rootView;
 
 
    }
    public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
        // An unresolvable error has occurred and Google APIs (including Sign-In) will not
        // be available.
        Log.d(TAG, "onConnectionFailed:" + connectionResult);
    }
}
voici le fragment liste_offres.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.codeeaters.taffer.MainActivity$PlaceholderFragment">
 
    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:id="@+id/offreRecyclerView">
 
 
 
 
    </android.support.v7.widget.RecyclerView>
</RelativeLayout>
et le fichier Offres.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="match_parent"
    android:layout_height="wrap_content">
<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:text="Type"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/typetxt"
        android:textStyle="normal|bold"
        android:textColor="@color/colorPrimary" />
 
    <TextView
        android:text="Salaire"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/salairetxt" />
 
    <TextView
        android:text="Domaine"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/domainetxt" />
 
    <TextView
        android:text="Poste"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/postetxt" />
 
    <TextView
        android:text="Contact"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/contacttxt" />
 
    <TextView
        android:text="Scolaire"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/scolairetxt" />
 
    <TextView
        android:text="Adresse"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/adressetxt" />
 
    <TextView
        android:text="Description"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/descriptiontxt" />
</LinearLayout>
</ScrollView>
le fichier DAO OffresDAO.java
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package com.codeeaters.taffer;
 
import java.util.Date;
 
/**
 * Created by pondikpa on 11/01/17.
 */
 
public class OffresDAO {
    public String postechoi,domainechoi,etudechoi,contactchoi,adressechoi,descriptionchoix,typechoi;
    private int offreid, salairechoi;
 
    public OffresDAO() {
    }
 
    public OffresDAO(String postechoi, String domainechoi, String etudechoi, String contactchoi, String adressechoi, String descriptionchoix, String typechoi, int offreid, int salairechoi) {
        this.postechoi = postechoi;
        this.domainechoi = domainechoi;
        this.etudechoi = etudechoi;
        this.contactchoi = contactchoi;
        this.adressechoi = adressechoi;
        this.descriptionchoix = descriptionchoix;
        this.typechoi = typechoi;
        this.offreid = offreid;
        this.salairechoi = salairechoi;
    }
 
    public int getOffreid() {
        return offreid;
    }
 
    public void setOffreid(int offreid) {
        this.offreid = offreid;
    }
 
    public String getPostechoi() {
        return postechoi;
    }
 
    public void setPostechoi(String postechoi) {
        this.postechoi = postechoi;
    }
 
    public String getDomainechoi() {
        return domainechoi;
    }
 
    public void setDomainechoi(String domainechoi) {
        this.domainechoi = domainechoi;
    }
 
    public String getEtudechoi() {
        return etudechoi;
    }
 
    public void setEtudechoi(String etudechoi) {
        this.etudechoi = etudechoi;
    }
 
    public String getContactchoi() {
        return contactchoi;
    }
 
    public void setContactchoi(String contactchoi) {
        this.contactchoi = contactchoi;
    }
 
    public String getAdressechoi() {
        return adressechoi;
    }
 
    public void setAdressechoi(String adressechoi) {
        this.adressechoi = adressechoi;
    }
 
    public String getDescriptionchoix() {
        return descriptionchoix;
    }
 
    public void setDescriptionchoix(String descriptionchoix) {
        this.descriptionchoix = descriptionchoix;
    }
 
    public String getTypechoi() {
        return typechoi;
    }
 
    public void setTypechoi(String typechoi) {
        this.typechoi = typechoi;
    }
 
    public int getSalairechoi() {
        return salairechoi;
    }
 
    public void setSalairechoi(int salairechoi) {
        this.salairechoi = salairechoi;
    }
}
Coordialement