logo
down
shadow

Android Very huge list of items with recyclerview best approach


Android Very huge list of items with recyclerview best approach

By : user6064168
Date : November 20 2020, 11:01 PM
I wish did fix the issue. You answer is RecyclerView, long, int and String. In terms of performances, RecyclerView is recycling views by itself when are no more visible and will provide a fast scroll and you can make more faster if you use cache. Also you can set null to views when view is recycled. In terms of memory, use basic objects like int, not Integer, long, not Logint, etc.
code :


Share : facebook icon twitter icon
RecyclerView Items have huge spaces between them

RecyclerView Items have huge spaces between them


By : Jason Park
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Try changing layout_height="match_parent" to layout_height="wrap_content". That should hopefully solve your problems.
android:- How to change the language of list items of recyclerview?

android:- How to change the language of list items of recyclerview?


By : R.lalaina
Date : March 29 2020, 07:55 AM
hope this fix your issue Activities creation are handle by the system , you should not call new WhateverActivity().
Instead you can use a Interface as a listener for example:
code :
public interface LocaleListener {
    void setLocale(String values)
}
    public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder>{

       String[] values;
       Context context1;
       private LocaleListener mListener;  //some change here

       public RecyclerViewAdapter(Context context2,String[] values2){

           values = values2;

           context1 = context2;
       }

       public static class ViewHolder extends RecyclerView.ViewHolder{

           public TextView textView;

           public ViewHolder(View v){

               super(v);

               textView = (TextView) v.findViewById(R.id.textview1);

           }
      }

     @Override
     public RecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){

         View view1 = LayoutInflater.from(context1).inflate(R.layout.recycler_view_items,parent,false);

         ViewHolder viewHolder1 = new ViewHolder(view1);

         return viewHolder1;
    }

    @Override
    public void onBindViewHolder(ViewHolder Vholder,final int position){

        Vholder.textView.setText(values[position]);

        Vholder.textView.setBackgroundColor(Color.parseColor("#ffc947"));

       Vholder.textView.setTextColor(Color.BLACK);
       Vholder.textView.setBackgroundResource(R.drawable.rounded_corner);

       Vholder.itemView.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               if(position == 4 && mListener != null){ // some change here
                   mListener.setLocale("hi");//calling function
               }
           }
       });

      }

    @Override
    public int getItemCount(){

        return values.length;
    }

    //some change here
    public void setLocaleListener(LocaleListener listener) {
        mListener = listener
    }
}
public class MainActivity extends AppCompatActivity implements LocaleListener{
   android.content.res.Resources res;

   RecyclerView recyclerView;

   Context context;
   String[] numbers;

   RecyclerView.Adapter recyclerView_Adapter;

   RecyclerView.LayoutManager recyclerViewLayoutManager;


   @Override
   protected void onCreate(Bundle savedInstanceState) {

      super.onCreate(savedInstanceState);

      setContentView(R.layout.activity_main);
      res = getResources();

      numbers = res.getStringArray(R.array.abc);

      getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
      getSupportActionBar().setCustomView(R.layout.action_bar);

      context = getApplicationContext();

      recyclerView = (RecyclerView) findViewById(R.id.recycler_view1);

    //Change 2 to your choice because here 2 is the number of Grid layout Columns in each row.
       recyclerViewLayoutManager = new GridLayoutManager(context, 2);

       recyclerView.setLayoutManager(recyclerViewLayoutManager);

       recyclerView_Adapter = new RecyclerViewAdapter(context,numbers);

       recyclerView_Adapter.setLocaleListener(this); // some change here

       recyclerView.setAdapter(recyclerView_Adapter);

   }

   @Override
   public void setLocale(String lang) {
       Locale myLocale = new Locale(lang);
       Resources res = context.getResources();
       DisplayMetrics dm = res.getDisplayMetrics();
       Configuration conf = res.getConfiguration();
       conf.locale = myLocale;
       res.updateConfiguration(conf, dm);
       Intent refresh = new Intent(this, MainActivity.class);
       startActivity(refresh);
       finish();
    }
}
Android: RecyclerView not showing List Items in a Fragment

Android: RecyclerView not showing List Items in a Fragment


By : Jean Mateus
Date : March 29 2020, 07:55 AM
help you fix your problem Ok, first off, your Fragment should be structured more like the following. In your onCreateView, just inflate the layout, and then in onViewCreated, that's when you bind/populate your information.
And we're also using newInstance, as that's the standard way to create new Fragments.
code :
public class CarFrontFragment extends Fragment {

    public ImageView bumper; // Do not use static views.
    public ImageView hood;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_car_front, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        // Bind your views.
        RecyclerView list = (RecyclerView) view.findViewById(R.id.front_recyclerview);
        bumper = (ImageView) view.findViewById(R.id.fbumperselected);
        hood = (ImageView) view.findViewById(R.id.hoodselected);

        // Create your layout manager.
        LinearLayoutManager layout = new LinearLayoutManager(getContext());
        list.setLayoutManager(layout);

        // Fetch your items.
        List<ItemObject> rowListItem = getAllItemList();

        // Set your adapter
        RecyclerViewAdapter adapter = new RecyclerViewAdapter(getContext(), rowListItem);
        list.setAdapter(adapter);

    }

    // Creating a new Fragment through newInstance.
    public static CarFrontFragment newInstance() {
        return new CarFrontFragment();
    }


    // Fetching items, passing in the View they will control.
    private List<ItemObject> getAllItemList(){
        List<ItemObject> allItems = new ArrayList<ItemObject>();

        allItems.add(new ItemObject("", R.drawable.hood_selected), hood);
        allItems.add(new ItemObject("", R.drawable.bumped_selected), bumper);

        return allItems;
    }
}
public class PagerAdapter extends FragmentStatePagerAdapter {

    public static final int NUM_OF_PAGES = 2;
    private static final int PAGE_WELCOME = 0;
    private static final int PAGE_CAR_FRONT = 1;

    public PagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        switch (position) {
            case PAGE_WELCOME:
                // Return a new instance of your Fragment.

            case PAGE_CAR_FRONT:
                return CarFrontFragment.newInstance();
        }
        return null;
    }

    @Override
    public int getCount() {
        return NUM_OF_PAGES;
    }
}
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewHolders> {

    private List<ItemObject> itemList;
    private Context context;

    public RecyclerViewAdapter(Context context, List<ItemObject> itemList) {
        this.itemList = itemList;
        this.context = context;
    }

    @Override
    public RecyclerViewHolders onCreateViewHolder(ViewGroup parent, int viewType) {
        View layoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_view_list, null);
        RecyclerViewHolders rcv = new RecyclerViewHolders(layoutView);
        return rcv;

    }

    @Override
    public void onBindViewHolder(RecyclerViewHolders holder, int position) {
        holder.photo.setImageResource(itemList.get(position).getPhoto());
        // Telling the holder about the View.
        holder.view = itemList.get(position).getView();
    }

    @Override
    public int getItemCount() {
        return itemList.size();
    }
}
public class RecyclerViewHolders extends RecyclerView.ViewHolder implements View.OnTouchListener {

    ImageView photo;
    public View view;

    public RecyclerViewHolders(View itemView) {
        super(itemView);
        itemView.setOnTouchListener(this);
        photo = (ImageView) itemView.findViewById(R.id.cardview);
    }

    @Override
    public boolean onTouch(View view, MotionEvent event) {
        switch (event.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_DOWN:
                this.view.setVisibility(View.VISIBLE);
                break;

            case MotionEvent.ACTION_POINTER_UP:
                this.view.setVisibility(View.GONE);
                break;
        }

        return true;
    }

}
How to make one placeholder items in Android RecyclerView Android list

How to make one placeholder items in Android RecyclerView Android list


By : wizardmorax
Date : March 29 2020, 07:55 AM
I hope this helps you . Well.
You can make it using one View class and then set up one background color and finally add one animation of the alpha property.
code :
<View
    android:id="@+id/my_view"
    android:layout_width="100dp"
    android:layout_height="20dp"
    android:background="#bbb"/>
<alpha
    android:fromAlpha="1.0"
    android:toAlpha="0.6" 
    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
    android:duration="1000"
    android:repeatMode="reverse"
    android:repeatCount="infinite"/>
<MockPlaceHolder
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layoutRes="@layout/placeholder_mock_main"
    app:repeact="5"/>
RecyclerView in android not showing list items

RecyclerView in android not showing list items


By : Libor Janovský
Date : March 29 2020, 07:55 AM
it fixes the issue I am implementing the recyler view in android.The arraylist shows the correct size of list,when i debug the code the adapter also get set.But list items are not displaying may be due createViewHolder and bindviewHolder.Below is the code of RecyclerViewAdapter
Related Posts Related Posts :
  • MPAndroidChart: unwanted spacing between XAxis and data line
  • How to parse JsonArray values in Android
  • Lifecycle of tabs in Android
  • What are the problems in using Intent to pass objects from one activity to another
  • Android : Multi line text EditText inside BottomSheetDialog
  • set savedInstanceState Bundle in Activity
  • Change progressDialog font to custom on Android
  • Why POT textures work slower than non-pot?
  • PersonAPI Google+ "PERMISSION_DENIED" Error
  • Using UserDialogs in Android
  • Get lightness of ambiance with react-native?
  • Lines between code in android
  • Sort list in two differents ways
  • Android Studio Change Array Value
  • Disable webview browser tester ( android )
  • Are there any cons of creating Singleton class with static field to communicate between activities in Android?
  • Change fragment background on create view dynamically
  • Android Getting coordinates of an image
  • unfortunately project has stopped after adding admob ads
  • Error inflating Class ImageView on RecyclerView
  • Android percent layouts
  • App Inventor - Input an item to a list and then properly display the list
  • Android, CountDownTimer latency
  • How to detect MotionEvent.ACTION_DOWN in service Android
  • code in HTML for sharing content over Phone gap interacting with other app as like ACTION_SEND indent on the native andr
  • Android - Displaying decimal as formatted fraction (and vice versa)
  • Android -FAB Behaviour with half list
  • Enabling externalNativeBuild with ABI split
  • Issue with multiscreen design
  • Upload binary file with retrofit 2 in Android
  • R.layout is'nt recogized by the studio
  • android - RecyclerView updating every second and have a longPressListener
  • What's the best way (in Android dev) to consume REST API (in addition to Retrofit)?
  • Which Android SDK Packages do I need for Cordova and Android 4+
  • Android & Retrofit2 - posting image file in multipart request
  • Calabash directory structure for testing both Android and iOS
  • javafxports 8.60.7 - using Back button on Android - none exit application
  • Create file from drawable to send with sendbird
  • Firebase app integration error
  • Xamarin No resource found that matches the given name (at 'colorAccent' with value '@color/accent ')
  • Will Firebase provide tests for other OS and does it support manual testing?
  • Android - Obtain self-signed server certificate and add to trusted keystore
  • Error:(25, 46) error: @InjectViews must be a List or array
  • What is the difference between 'Make' and 'Gradle-aware Make'?
  • How to know if user has verified his/her email address
  • Importing Android-Download-Manager library results "failed to resolve"?
  • Showing particular area in google PlacePicker
  • Sharing pdf to Evernote not working in Android
  • Android : Google signin is not working in release mode
  • How to save an intent object and later retrieve it
  • Convert YUV Image into greyscale Image - Same Result as RGB to Grayscale?
  • bulkTransfer makes the application crash
  • How to aspect fill programmatically? [Android]
  • I lost my key store password, I want to update my app on plays store with same keystore
  • How to find the minimum and maximum dates from three tables even if there is no date in one table in android sqlite
  • Unparseable date: "10:40:54" (at offset 0)
  • Keep count of consumable in-app purchases using Firebase Realtime Database
  • Proguard with Parceler and Realm
  • Check whether the file is already exists Android not working
  • Update value to mutiply objects by Transaction in Firebase
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com