logo
down
shadow

how do I open another fragment after selecting the image in recycler view?


how do I open another fragment after selecting the image in recycler view?

By : user2174915
Date : October 16 2020, 08:10 PM
With these it helps Here is An example for You paste as it is. Make constructor which will have an interface as parameter in adapter and override it in Fragment.
Your Fragment Code will look like this.
code :
public class CorporateFragment extends Fragment {

    private final int LAYOUT_LISTCORPORATE_FRAGMENT = R.layout.corporate_membership;

    private View v;
    private Date date;

    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;

    public CorporateFragment() {

    }

    private int[] images = {
            R.drawable.sample1,
            R.drawable.sample2
    };

    public static CorporateFragment newInstance(Date date) {
        CorporateFragment fragment = new CorporateFragment();
        Bundle args = new Bundle();
        //args.putSerializable(ARG_DATE,date);
        fragment.setArguments(args);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        // Inflate the layout for this fragment
        v = inflater.inflate(LAYOUT_LISTCORPORATE_FRAGMENT, container, false);
        ButterKnife.bind(this, v);

        return v;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {

        recyclerView = (RecyclerView) v.findViewById(R.id.recyclerView);
        final CorporateAdapter listAdapter = new CorporateAdapter(getActivity(), images, new CorporateAdapter.onItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                /////////////////// do your on Click Stuff here...
                /////////// for ex .. go to next fragment
            }
        });
        recyclerView.setAdapter(listAdapter);
        layoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);

    }
}
 public class CorporateAdapter extends RecyclerView.Adapter<CorporateAdapter.MyViewHolder> {

     Context context;
     private int[] images;
     onItemClickListener onItemClickListener;

     public CorporateAdapter(Context context, int[] images, CorporateAdapter.onItemClickListener onItemClickListener) {
         this.context = context;
         this.images = images;
         this.onItemClickListener = onItemClickListener;
     }

     @Override
    public MyViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.corporate_list_row, viewGroup, false);
        final MyViewHolder vHold = new MyViewHolder(view);
        return vHold;
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, final int position) {


        ((MyViewHolder) holder).bindView(position);

        holder.mImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onItemClickListener.onItemClick(view,position);
            }
        });

    }


    @Override
    public int getItemCount() {
        return images.length;
    }

    private class MyViewHolder extends RecyclerView.ViewHolder {

        private ImageView mImageView;

        public MyViewHolder(View itemView) {
            super(itemView);
            mImageView = (ImageView) itemView.findViewById(R.id.showImage);

        }

        public void bindView(int position) {

            mImageView.setImageResource(images[position]);

        }

    }

    public interface onItemClickListener{
        void onItemClick(View view , int position);
    }
}


Share : facebook icon twitter icon
Why isn't my Recycler adapter/Recycler view not connecting to the fragment and not showing?

Why isn't my Recycler adapter/Recycler view not connecting to the fragment and not showing?


By : Vrushala
Date : March 29 2020, 07:55 AM
this will help Cast_detail_fragment:
code :
 public void setcastlist(ArrayList<cast_class_details> castlist){
    this.castlist=castlist;
    notifyItemRangeChanged(0,castlist.size());
  //  Toast.makeText(this,String.valueOf(castlist.size()),Toast.LENGTH_SHORT).show();
}
  public void setcastlist(ArrayList<cast_class_details> castlist){
    this.castlist=castlist;
    notifyDataSetChanged();
  //  Toast.makeText(this,String.valueOf(castlist.size()),Toast.LENGTH_SHORT).show();
}
I am attaching a image to a recycler view which is being downloaded from server, but recycler view is not showing any im

I am attaching a image to a recycler view which is being downloaded from server, but recycler view is not showing any im


By : Giannis Ioannou
Date : March 29 2020, 07:55 AM
I hope this helps . You are missing the update notice for your adapter (which displays the data).
Everytime you update your List, you need to call
code :
adapter.notifyDataSetChanged();
//if you only change one item, and use recyclerview, call:
adapter.notifyItemChanged(); 
What is proper logic to update text view on fragment after change in item of recycler list view

What is proper logic to update text view on fragment after change in item of recycler list view


By : Yusuf timurtaş
Date : March 29 2020, 07:55 AM
like below fixes the issue I had both Adapter and Fragment classes in separate files. I merged both class, created private inner Adapter class in Fragment class and a method to recalculate selling price multiplied by quantity and update it in textView inside my quantity setOnItemSelectedListener, on delete listener and on web service call.
code :
private void calculateGrandTotal(List<GetShoppingCartBean> cartBeans){
    double total = 0;
    for(GetShoppingCartBean cart: cartBeans){
        total += (cart.getSellingPriceWithOffer() * cart.getQuantity());
    }
    String price = grandPriceSuffix(total);
    grandAmount.setText(price);
}
Recycler View Wrongly selecting View Item while performing multi-Select

Recycler View Wrongly selecting View Item while performing multi-Select


By : s.b
Date : March 29 2020, 07:55 AM
I wish this help you You are doing most of the view manipulation in Onclick listener, you should move that to you adapter onBindView, because even if you set in Onclick listener, it will modify when user scroll.
I am not giving complete view manipulation, I am just giving the hint how we should do.
code :
@Override
public void onBindViewHolder(final ContactHolder holder, int position) {
    pos = position;
    final Contact contact = contactList.get(pos);

    holder.colg.setText(contact.getColg());
    holder.name.setText(contact.getName());
    holder.job.setText(contact.getJob());


    if (contact.getImage() != null)
        holder.img.setImageBitmap(Utility.getPhoto(contact.getImage()));


    if (multiselect_list.contains(contactArrayList.get(position))) { // May be you should check form your fragment or actvity using listeners
        holder.mentee.setBackgroundColor(ContextCompat.getColor(ContactsActivity.this, R.color.colorPrimary));
        holder.participant.setBackgroundColor(ContextCompat.getColor(ContactsActivity.this, R.color.colorPrimary));

        holder.mentee.setVisibility(View.VISIBLE);
        holder.participant.setVisibility(View.VISIBLE);
    } else {

        holder.mentee.setVisibility(View.GONE);
        holder.participant.setVisibility(View.GONE);
    }

}
Recycler view show wrong items in fragment with multiple view holders

Recycler view show wrong items in fragment with multiple view holders


By : Khaled Ahmed
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I wrote a sample app that does this and tested. So if you are still having issues, please feel free to download this. I will leave it up for a month at least.
Sample Dynamic ViewHolders
Related Posts Related Posts :
  • How to employ keyed-hash message authentication code (HMAC) with Android Keystore
  • Prevent inviting existing users or previously invited
  • How to overwrite windowSoftInputMode using edit-config tag in cordova
  • Difference between Loader and AsyncTask
  • In Firebase Android, retrieve the value of a child node and save it in a boolean variable
  • when i scroll the custom list in my android app then the favorite icon which is part of the custom adapter changes on it
  • adding room dependency gives manifest merge error
  • Visibility of RelativeLayout change on scrolling Gridview
  • Strange LiveData behavior vs ObservableField
  • Which layout is used for clash of clans home screen? We can scroll it horizontal as well as vertical. Please illuminate
  • RxJava: Know when observable is finished and return Boolean Observable to the caller
  • how to use savedInstanceState to save camera information when the orientation change occure
  • Style React-Native via Styles.xml
  • Keyboard won't show after calling InputMethodManager.showSoftInput
  • Compiling ffmpeg for Android on OSX
  • Button does not get clicked on the first attempt
  • AR Core performance, learning curve and comparison with other frameworks
  • Codename one : Attaching images to email message fails
  • Error: Unsupported type 'viewItem' in Android build
  • setLayoutParams on ConstraintLayout does not change size
  • How to profile the fetch time of the android gradle libraries
  • Kotlin setOnclickListener
  • Naming convention for methods returning RxJava's Completable
  • Conv3D not working
  • FFmpeg audio video merge command
  • Do you have to use gradle-experimental for JNI?
  • How to get key hashes for facebook for facebook app?
  • ZXing not calling onActivityResult, When scanning QR Code
  • Integration of Android Native module with existing Xamarin Native Project
  • Restore RecyclerView state after rotating
  • ViewModelProviders java.lang.RuntimeException trying to instantiate class which inherit AndroidViewModel
  • SKD19 vs SDK24 - Usage of API documented as @since 1.8+
  • filter option in list view fragment activity
  • Picture from camera not showing up in second activity
  • How to change imageview according to screen size
  • How to copy Android Studio project to remote Git (NOT GitHub) server
  • How to get React-Native to announce specific accessibility message via AccessibiliyManager?
  • Change colors of com.tech.freak.wizardpager.ui.StepPagerStrip
  • Android fullscreen activity shows ActionBar
  • Turn on the screen when timer calls onFinish()
  • Would like a bit of clarification with SQLite database's onUpgrade method
  • Use ObjectBox with Libgdx
  • How to make combine Gregorian and Hijri calendar in Android?
  • Try to read text file from sdcard in other language
  • "App not installed" message when installed apk
  • How to execute a designated test suite class in Firebase Test Lab
  • play music with background service
  • background not visible on LG G3
  • should every View have an id?
  • Realm object server sync on low connection.
  • Correct way to add more views to adapter
  • Getting error in android support library
  • Instant app zip uploading error
  • "No emulator installed" error in Android Studio even though Intel HAXM is up and running
  • AsyncTask without leaks
  • SQLiteException : No such table found whereas a table was created
  • Using @Component.Builder with constructor params
  • No injector was found for fragment dagger 2.11
  • Android Volley Https SSL self signed and Google Maps API
  • Why does the onClickListener not work anymore in this example?
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org