RecyClerview上的更新值单击“侦听器”



i使用firebase上传文件并在recyclerview中查看应用程序当我单击任何项目时,都应将我带到另一个活动并在WebView中查看文件时,问题是当我单击任何项目时,将第一个文件上传到firebase时,当我单击任何项目时,我需要此项目

public class postShows extends AppCompatActivity {
    private RecyclerView postlist;
    private DatabaseReference mdatabase;
    private FirebaseAuth auth;
    ImageView imagepostl;
    TextView textname;
    String  ma,mmmmmm;
    PostUtils m;

    Context context;
    public static String imageURL, fileType,fileNAme;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_post_shows);
        mdatabase = FirebaseDatabase.getInstance().getReference().child(PostNew.item);
        auth = FirebaseAuth.getInstance();
        imagepostl = (ImageView) findViewById(R.id.imagefilesource);
        textname = (TextView) findViewById(R.id.textfilename);
        postlist = (RecyclerView) findViewById(R.id.postRecycle);
        postlist.setHasFixedSize(true);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        postlist.setLayoutManager(linearLayoutManager);
    }
    @Override
    protected void onStart() {
        super.onStart();
        FirebaseRecyclerAdapter<PostUtils, PostViewHolder> firebaseRecyclerAdapter = new
                FirebaseRecyclerAdapter<PostUtils, PostViewHolder>(
                        PostUtils.class,
                        R.layout.post_row,
                        PostViewHolder.class,
                        mdatabase

                )
                {

                    @Override
                    protected void populateViewHolder(PostViewHolder viewHolder, PostUtils m, int position) {
                        fileType = m.getfiletype();
                        fileNAme=m.getFileName();
                        //   viewHolder.setDesc(m.getDescription());
                        if (m.getfiletype().equals("application/vnd.openxmlformats-officedocument.wordprocessingml.document")) {
                            // imagepostl.setImageResource(R.drawable.word);
                            viewHolder.setFileName(m.getFileName());
                            viewHolder.setWord(imagepostl);
                            mmmmmm= viewHolder.setImageURL(ma,m);
                        } else if (m.getfiletype().equals("application/pdf")) {
                            viewHolder.setFileName(m.getFileName());
                            viewHolder.setPDF(imagepostl);
                            mmmmmm= viewHolder.setImageURL(ma,m);

                        } else if (m.getfiletype().contains("image")) {
                            viewHolder.setimage(imagepostl);
                            mmmmmm= viewHolder.setImageURL(ma,m);

                        } else {
                            viewHolder.setFileName(m.getFileName());
                            {
                                viewHolder.setimage(imagepostl);
                            }
                        }
                    }
                    @Override
                    public PostViewHolder onCreateViewHolder(final ViewGroup parent, int viewType) {
                        PostViewHolder viewHolder = super.onCreateViewHolder(parent, viewType);
                        viewHolder.setOnClickListener(new PostViewHolder.ClickListener() {
                            @Override
                            public void onItemClick(View view, int position) {
                                Intent intent = new Intent(Kasittestbank.getAppContext(), Kasit.class);
                                intent.putExtra("imageURL",mmmmmm);
                                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                Kasittestbank.getAppContext().startActivity(intent);
                            }
                            @Override
                            public void onItemLongClick(View view, int position) {
                                Toast.makeText(Kasittestbank.getAppContext(), "Item long clicked at " + position, Toast.LENGTH_SHORT).show();
                            }
                        });
                        return viewHolder;
                    }
                };
        postlist.setAdapter(firebaseRecyclerAdapter);
    }

    public static class PostViewHolder extends RecyclerView.ViewHolder  {
        View mview;
        Bitmap bitmap;
        FileOpen fileOpen;

        public PostViewHolder(View itemView) {
            super(itemView);
            mview = itemView;
            mview.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mClickListener.onItemClick(v, getAdapterPosition());
                }
            });
        }
        private PostViewHolder.ClickListener mClickListener;
        //Interface to send callbacks...
        public interface ClickListener {
            public void onItemClick(View view, int position);
            public void onItemLongClick(View view, int position);
        }
        public void setOnClickListener(PostViewHolder.ClickListener clickListener) {
            mClickListener = clickListener;
        }

        public void setFileName(String name) {
            TextView textName = (TextView) mview.findViewById(R.id.textfilename);
            textName.setText(name);

        }

        public void setWord(ImageView imageResourses) {
            ImageView imageView = (ImageView) mview.findViewById(R.id.imagefilesource);
            imageView.setImageResource(R.drawable.word);

        }
        public void setPDF(ImageView imageResourses) {
            ImageView imageView = (ImageView) mview.findViewById(R.id.imagefilesource);
            imageView.setImageResource(R.drawable.pdf);

        }
        public void setimage(ImageView imageResourses) {
            ImageView imageView = (ImageView) mview.findViewById(R.id.imagefilesource);
            imageView.setImageResource(R.drawable.image);

        }
                public String setImageURL(String url, PostUtils maa){
                url=maa.getImageUrl();
                    return url;
                }

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu, menu);
        return super.onCreateOptionsMenu(menu);
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {

            case R.id.logut:

                Logut();
                startActivity(new Intent(getApplicationContext(), LoginActivity.class));
        }
        return super.onOptionsItemSelected(item);
    }
    public void Logut() {
        auth.signOut();
        finish();
    }
}

定义回收文章时,应覆盖的一种方法是onbindviewholder。该方法的内部是定义回复库的每个元素的内容。

因此,如果您想单击每行,请认为您需要这样的东西:

@Override
public void onBindViewHolder(PostViewHolder postViewHolder, int i) {
  postViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          //Definde what happend when the item is clicked
          //To identify which row, you can use postViewHolder.getAdapterPosition();
        }
    });
}

让我知道是否有效。

相关内容

  • 没有找到相关文章

最新更新