0

I want to display html text and image together within recyclerview but ı guess ı couldnt. when ı used to one button it works. But ı try to use recyclerview it doesnt work. anyone help me? meanwhile ı am too newbie on android. thanks everyone.

    public MyViewHolder(View itemView) {
        super(itemView);

        itemView.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View position) {
           int mposition = getLayoutPosition();
              callActivities(mposition);
           }

            private void callActivities(int mposition) {
               if (mposition == 0) {
                   image.setImageResource(R.drawable.bb);
                   String htmlAsString = getString(R.string.bb);
                   Spanned htmlAsSpanned = Html.fromHtml(htmlAsString);
                   vh= (TextView) findViewById(R.id.vh);
                   vh.setText(htmlAsSpanned);
                   ((TextView)findViewById(R.id.vh)).setVisibility(View.VISIBLE);  ((TextView)findViewById(R.id.baslik)).setVisibility(View.GONE);
               } else if (mposition == 1){
                   image.setImageResource(R.drawable.db);
                   String htmlAsString = getString(R.string.db);
                   Spanned htmlAsSpanned = Html.fromHtml(htmlAsString);
                   vh= (TextView) findViewById(R.id.vh);
                   vh.setText(htmlAsSpanned);
                   ((TextView)findViewById(R.id.vh)).setVisibility(View.VISIBLE);  ((TextView)findViewById(R.id.baslik)).setVisibility(View.GONE);


               } else if (mposition == 2){
                   image.setImageResource(R.drawable.cb);
                   String htmlAsString = getString(R.string.cb);
                   Spanned htmlAsSpanned = Html.fromHtml(htmlAsString);
                   vh= (TextView) findViewById(R.id.vh);
                   vh.setText(htmlAsSpanned);
                   ((TextView)findViewById(R.id.vh)).setVisibility(View.VISIBLE);  ((TextView)findViewById(R.id.baslik)).setVisibility(View.GONE);
               }      ((TextView)findViewById(R.id.vh)).setVisibility(View.VISIBLE);  ((TextView)findViewById(R.id.baslik)).setVisibility(View.GONE);
               } 
            }
        });

}

}

danyali
  • 1
  • 4

1 Answers1

0

Let me see if I got it right.. this example I am using should help you a bit

public class YourAdapter extends RecyclerView.Adapter<YourAdapter.MyViewHolder>{

    class MyViewHolder extends RecyclerView.ViewHolder{
        private ImageView imageView;
        private TextView textview;

        private MyViewHolder(View view){
            super(view);
            //here you will be able to retrieve the views inside each item of the recyclerview
            imageView = view.findViewById(R.id.imageView);
            textView = view.findViewById(R.id.textView);
        }
    }

    public YourAdapter(){//constructor}

    @Override
    public int getItemCount(){
        return 0;
    }

    @Override
    public YourAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
        View view= LayoutInflater.from(parent.getContext())
            .inflate(R.layout.layour_for_rv_item, parent, false);

        return new YourAdapter.MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(YourAdapter.MyViewHolder holder, position){
        // here you link your data 
        // for instance set the text to the textView
    }
}
Ionut J. Bejan
  • 734
  • 11
  • 28