android-adapter

Shuffling an Adapter [duplicate]

霸气de小男生 提交于 2020-08-06 07:01:58
问题 This question already has answers here : Random shuffling of an array (29 answers) Closed 7 years ago . I am using an Adapter : final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1); and I want to shuffle the contents of it, however I discovered that Collections.shuffle(adapter); does not work. Is there another method to do this? While keeping the format of adapter i.e. not changing it to a List 回答1: Of course Collections

Is there a better way of getting a reference to the parent RecyclerView from the adapter?

寵の児 提交于 2020-07-31 06:47:08
问题 I have a use case where I need a reference to the parent RecyclerView from inside the adapter, specifically inside the onBindViewHolder method. So far what I am doing is assigning it to a private class member in the onCreateViewHolder method passing along the viewGroup parent arg like so: private ViewGroup mParent; @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // inflater logic. mParent = parent; } And referencing the parent RecyclerView in onBindViewHolder

Not able to print all childs from my firebase database

你。 提交于 2020-07-16 08:00:07
问题 I want to print all dates(childs) details from 5th of july to 7th of july from my database but i only get top date(child)[7th july] as my output instead of all of the child nodes** Here is my reference where i get values from database and put into RecyclerView adapter DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Dateinfo").child(firebaseUser.getUid()); reference.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(@NonNull

Android : How to use mFusedLocationClient callback (resulting location) in current mainthread

大城市里の小女人 提交于 2020-06-27 19:32:10
问题 Following is my adapter for a RecyclerView where i need to update one of the TextView which shows distance of current location to another location . Now , to get the current location , i am using mFusedLocationClient.requestLocationUpdates(mFusedLocationRquest,mLocationCallback,null); If i am going with the below code and have just enabled gps in app with runtime permission , i face NPE on line : float distance = updatedLoc.distanceTo(des); App does not crash when i open with gps already

RecyclerView with different types and different adapter

故事扮演 提交于 2020-04-30 11:11:27
问题 and thank you for your attention to my request. I'm a newbie on Andorid Studio and I'm developing an App, it has to show a list of Events, Courses and News. There is a DrawerLayout which allow navigating into Event's, course's and news's area, each area has each specific RecyclerView, but into the home activity, I have to show all the items (Event, Course and News). I create an Adapter for each item (because they have different properties) and each section (fragment) works properly but now I

How to display a date like Whatsapp on scrolling ListView

*爱你&永不变心* 提交于 2020-04-11 11:36:10
问题 How can I show dates in an app when I scroll the ListView like in WhatsApp? See the below image for clarity: When I scroll the ListView, the date gets displayed over the list. If you still did not understand my question please open your WhatsApp, go to any group & start scrolling: you will see the date getting displayed for older texts. 回答1: To show date like this screenshot, you can use val firstVisiblePosition = layoutManager.findFirstVisibleItemPosition() if (getDateFromFirebaseTime

RecyclerView / DiffUtils animation when dataset change without full refresh

↘锁芯ラ 提交于 2020-04-10 05:23:34
问题 I would like two things : To not reload / refresh the adapter when i delete an item inside RecyclerView (no use of notifyDatasetChanged ). To do so i am using DiffUtils which works perfectly fine. But i also would like to keep the DefaultItemAnimator of the RecyclerView which has apparently no effect with DiffUtils. So my question is : How can i remove / update an item without refreshing all the dataset AND keep a similar animation to the DefaultItemAnimator ? I know many posts gives answers

RecyclerView / DiffUtils animation when dataset change without full refresh

人盡茶涼 提交于 2020-04-10 05:23:13
问题 I would like two things : To not reload / refresh the adapter when i delete an item inside RecyclerView (no use of notifyDatasetChanged ). To do so i am using DiffUtils which works perfectly fine. But i also would like to keep the DefaultItemAnimator of the RecyclerView which has apparently no effect with DiffUtils. So my question is : How can i remove / update an item without refreshing all the dataset AND keep a similar animation to the DefaultItemAnimator ? I know many posts gives answers

How to Refresh ListView in Fragment that is filled with BaseAdapter?

倾然丶 夕夏残阳落幕 提交于 2020-03-14 09:22:34
问题 I want to Refresh a ListView in a Fragment when a Dialog is closed. Until now the refresh only works when I restart the app and I don't really know why. Here are the classes: This is the Fragment with the ListView on it, that i want to refresh, when the Dialog is closed. public class RegisterListFragment extends Fragment { public static final String TAG = "RegisterListFragment"; RegisterListAdapter adapter; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,

How to Refresh ListView in Fragment that is filled with BaseAdapter?

折月煮酒 提交于 2020-03-14 09:16:51
问题 I want to Refresh a ListView in a Fragment when a Dialog is closed. Until now the refresh only works when I restart the app and I don't really know why. Here are the classes: This is the Fragment with the ListView on it, that i want to refresh, when the Dialog is closed. public class RegisterListFragment extends Fragment { public static final String TAG = "RegisterListFragment"; RegisterListAdapter adapter; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,