如何在单击FirbaseRecyclerAdapter内容时显示对话框视图

时间:2018-10-03 05:35:49

标签: firebase firebase-realtime-database android-recyclerview recycler-adapter clickable

MainActivity类的类 需要的解决方案:单击适配器中的列表项时,应在包含相同标题和图像的对话框视图中打开

公共类MainActivity扩展了AppCompatActivity {

LinearLayoutManager mLayoutManager;
SharedPreferences mShared;
RecyclerView recycler;
FirebaseDatabase mData;
DatabaseReference mRef;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    recycler = (RecyclerView) findViewById(R.id.recycler);
    recycler.setLayoutManager(mLayoutManager);
    recycler.setHasFixedSize(true);


    mData = FirebaseDatabase.getInstance();
    mRef = mData.getReference("Data");

}

@Override
protected void onStart() {
    super.onStart();


    FirebaseRecyclerAdapter<Model, ViewAdapter> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Model, ViewAdapter>(
            Model.class,
            R.layout.row,
            ViewAdapter.class,
            mRef


    )


    {
        @Override
        protected void populateViewHolder(ViewAdapter viewHolder, Model model, int position) {


            viewHolder.setDetails(getApplicationContext(), model.getTitle(), model.getDescription(),model.getImage());

        }


        @Override
        public ViewAdapter onCreateViewHolder(ViewGroup parent, int viewType) {


            return super.onCreateViewHolder(parent, viewType);
        }
    };


    recycler.setAdapter(firebaseRecyclerAdapter);

}

ViewAdapter类

公共类ViewAdapter扩展了RecyclerView.ViewHolder {

View v;


public ViewAdapter(View itemView) {
        super(itemView);
        v = itemView;





}





public void setDetails(Context ctx, String title, String description,String image ){


    TextView mText = (TextView) v.findViewById(R.id.mTitle);
    TextView mDesc = (TextView) v.findViewById(R.id.mdescrip);
    ImageView mImage= (ImageView) v.findViewById(R.id.mImage);



    mText.setText(title);
    mDesc.setText(description);
    Picasso.get().load(image).into(mImage);







}

所需的解决方案:单击适配器中的列表项时,应在包含相同标题和图像的对话框视图中打开

0 个答案:

没有答案