android-adapter

Dynamically change the number of columns of a GridLayoutManager

久未见 提交于 2019-12-03 16:31:53
问题 I am actually using a GridLayoutManager with two columns in my app and I would like to have one column depending on the view type used. Here is the code I have in the method "onCreateView()" of my fragment : // Recycler view for users usersList = (RecyclerView) mView.findViewById(R.id.usersList); // Layout manager (grid of users layoutManager = new GridLayoutManager(mContext, 2); usersList.setLayoutManager(layoutManager); // ArrayList of users users = new ArrayList<User>(); // Set the adapter

Save State and Restore State in FragmentStatePagerAdapter

风格不统一 提交于 2019-12-03 15:01:30
I a using ViewPager with FragmentStatePageAdapter on my screen I have 5 pages which has lots of images and views. Currently I have mViewPager.setOffscreenPageLimit(1); so only current, previous and next will be in memory and other 2 will be destroyed. But for that destroyed fragments I want to make use of saveState() and restoreState() of the adapter to maintain its state so when I come back to that screen it will anyways go to onCreateView() of that fragment what will maintain state also. Having mViewPager.setOffscreenPageLimit(4); is not a good option as it has memory issues. I searched a

get fragment by tag or id from tablayout ,android

耗尽温柔 提交于 2019-12-03 11:58:02
问题 i use this tutorial for creating tab. and now i have a recyclerview in each fragment and i want to notify them from mainactivity. how to access the adapter in fragment? i use this for calling refreshData() method in fragment: TabFragment1 tabFragment = (TabFragment1) getSupportFragmentManager().findFragmentByTag(TabFragment1.class.getSimpleName()); if (tabFragment != null) { tabFragment.refreshData(); } but that return null. mainActivity: TabLayout tabLayout = (TabLayout) findViewById(R.id

Make last Item / ViewHolder in RecyclerView fill rest of the screen or have a min height

你。 提交于 2019-12-03 11:41:58
I'm struggeling with the RecyclerView. I use a recycler view to display the details of my model class. //My model class MyModel { String name; Double latitude; Double longitude; Boolean isOnline; ... } Since some of the values might not be present, I use the RecyclerView with custom view types (one representing each value of my model). //Inside my custom adapter public void setModel(T model) { //Reset values itemCount = 0; deviceOfflineViewPosition = -1; mapViewPosition = -1; //If device is offline, add device offline item if (device.isOnline() == null || !device.isOnline()) {

How to use ButterKnife inside adapter

 ̄綄美尐妖づ 提交于 2019-12-03 11:04:35
I would like to use ButterKnife to bind my views inside listView adpater. I tried this, but i can not simply use my "spinner" var. public class WarmSpinnerAdapter extends ArrayAdapter<Warm> { Context context; public WarmSpinnerAdapter(Context context, int resource, Warm[] objects) { super(context, resource, objects); } @Override public View getView(int position, View convertView, ViewGroup parent) { View v = LayoutInflater.from(context).inflate(R.layout.item_spinner, null); return v; } @OnClick(R.id.spinner) public void onClick() { //open dialog and select } static class ViewHolder { @BindView

PagedListAdapter jumps to beginning of the list on receiving new PagedList

[亡魂溺海] 提交于 2019-12-03 08:16:54
I'm using Paging Library to load data from network using ItemKeyedDataSource . After fetching items user can edit them, this updates are done inside in Memory cache (no database like Room is used). Now since the PagedList itself cannot be updated (discussed here ) I have to recreate PagedList and pass it to the PagedListAdapter . The update itself is no problem but after updating the recyclerView with the new PagedList , the list jumps to the beginning of the list destroying previous scroll position. Is there anyway to update PagedList while keeping scroll position (like how it works with Room

How to set two adapters to one RecyclerView?

喜你入骨 提交于 2019-12-03 07:34:52
问题 I am developing an android app in which I'm storing two different types of information on 'FirebaseDatabase`. Then in the MainActivity , I'm retrieving them and showing to users in a RecyclerView . Both information are meant to be shown in different layouts, i.e., the layouts for both of them are different and that's why I have two make two different Model class and now have 2 different adapters. I'm using FastAdapter by @MikePenz So, what I did is I set the adapter on recyclerview in the

FragmentPagerAdapter notifyDataSetChanged not working

五迷三道 提交于 2019-12-03 04:45:58
问题 I got a FragmentPagerAdapter. It's getItem method can return a fragment according to data it has from the outside. After I update the data its suppose to display I call notifyDataSetChanged and yet nothing happened. I DID override the getItemPosition method to return POSITION_NONE : public static class TabsAdapter extends FragmentPagerAdapter implements TabHost.OnTabChangeListener, ViewPager.OnPageChangeListener { private final Context mContext; private final TabHost mTabHost; private final

RecyclerView onBindViewHolder only called when getItemViewType changes

喜你入骨 提交于 2019-12-03 04:14:47
问题 I have a viewholder with multiple viewtypes. When scrolling onBindViewHolder is only called when getItemViewType changes value. This causes my list items to not be updated properly. Is this a bug? Or I'm i doing something wrong here. This seems very strange behaviour from the new recyclerView class. Here is my adapter: package se.davison.smartrecycleradapter; import android.content.Context; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.util

Volley Plus OutOfMemoryError in List Adapter

不羁的心 提交于 2019-12-02 21:24:26
问题 I am using Volley Plus library. I am showing ListView with image and text view with no error, but when i scroll up and down lots of time in this listview it get OutOfMemoryError and crash the application. Here is LogCat : java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Try again at java.lang.Thread.nativeCreate(Native Method) at java.lang.Thread.start(Thread.java:1063) at com.android.volley.RequestQueue.start(RequestQueue.java:135) at com.android.volley.cache.plus