`我正在重播“新闻”中的数据,如屏幕截图所示,并且我尝试从“信息”中检索相同的程序,但在android中,它显示来自新闻的数据,但不是来自我已经尝试了很多的信息,但是我无法解决这个请求帮助。
我这样做:
DatabaseReference mInfo= FirebaseDatabase.getInstance().getReference().child("Info");
DatabaseReference mDatabase= FirebaseDatabase.getInstance().getReference().child("News");
它适用于新闻,但不适用于信息。
代码在这里`
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
/**
* Created by HP INDIA on 08-Apr-17.
*/
public class FragmentOne extends Fragment {
public FragmentOne() {}
private RecyclerView mInfoLists;
private DatabaseReference mDatabase;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.tab_one, container, false);
super.onCreate(savedInstanceState);
mInfoLists=(RecyclerView)rootView.findViewById(R.id.mInfoLists);
mDatabase= FirebaseDatabase.getInstance().getReference().child("Info");
mDatabase.keepSynced(true);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
linearLayoutManager.setReverseLayout(true);
linearLayoutManager.setStackFromEnd(true);
mInfoLists.setHasFixedSize(true);
mInfoLists.setItemViewCacheSize(20);
mInfoLists.setDrawingCacheEnabled(true);
mInfoLists.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_AUTO);
mInfoLists.setLayoutManager(linearLayoutManager);
FirebaseRecyclerAdapter<OrgInfo,OrgInfoViewHolder> firebaseRecyclerAdapter=new FirebaseRecyclerAdapter<OrgInfo,OrgInfoViewHolder>(
OrgInfo.class,
R.layout.home_list_item,
OrgInfoViewHolder.class,
mDatabase
){
@Override
protected void populateViewHolder(OrgInfoViewHolder viewHolder, OrgInfo model, int position) {
viewHolder.setTitle(model.getTitle());
viewHolder.setDesc(model.getDescription());
}
};
mInfoLists.setAdapter(firebaseRecyclerAdapter);
return rootView;
}
public static class OrgInfoViewHolder extends RecyclerView.ViewHolder {
View mView;
public OrgInfoViewHolder(View itemView) {
super(itemView);
mView=itemView;
}
public void setTitle(String title) {
TextView post_title=(TextView)mView.findViewById(R.id.name);
post_title.setText(title);
}
public void setDesc(String desc) {
TextView post_title=(TextView)mView.findViewById(R.id.address);
post_title.setText(desc);
}
}
`
这就是我显示数据的方式。对于新闻部分,代码正在工作,而信息则不是