android-adapter

Android more complex ListView tutorial [closed]

陌路散爱 提交于 2019-12-06 04:23:59
Closed. This question is off-topic . It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I've just started out coding for Android but am struggling to get my head around listviews. For example I need to understand how I can show another listview when clicking on an item in the first listview. Also how I can display a textview when clicking on an item in a listview. If anyone knows of any good tutorials or examples please let me know. Thanks a lot trgraglia Here are some links for you are looking for

How to fix notifyDataSetChanged/ListView problems in dynamic Adapter wrapper Android

非 Y 不嫁゛ 提交于 2019-12-06 03:27:38
问题 Summary: Trying to dynamically add heading rows to a ListView via a custom adapter wrapper. ListView is having trouble keeping the scroll position in sync. Runnable demo project provided. I would like to dynamically add items to a list based on the values in a CursorAdapter, several positions ahead of what the user is currently viewing. To do this, I have an adapter that wraps the CursorAdapter and keeps the new content indexed in a SparseArray. The ListView needs to be updated when items are

HorizontalScrollView: CustomAdapter with getView() doesn't reuse convertViews like ListView

不想你离开。 提交于 2019-12-06 00:31:46
In one of my past projects I implemented a "Time Picker Carousel". It is based on a HorizontalScrollView . The user can pick a time while scrolling this view. The time value is calculated from the X-Offset of the HorizontalScrollView . I wanted to share this project at github, but while cleaning up the code I realized some bad performance issue. The HorizontalScrollView is populated with a custom ArrayAdapter . The getView() uses a Holder for the convertView . I thought it might work as an adapter within a ListView , so only the visible items are rendered and reused if they will be destroyed.

Dynamically remove an item from a ViewPager with FragmentStatePagerAdapter

谁说我不能喝 提交于 2019-12-05 19:39:41
问题 There are quite a few discussions around this topic ViewPager PagerAdapter not updating the View Update ViewPager dynamically? Removing fragments from FragmentStatePagerAdapter I have tried various solutions (including the invalidation with POSITION_NONE ) . But I still donT know how to remove an item properly. What happens is either I get a blank page (meaning the fragment is destroyed, but the instantiateItem was not called for a replacement) or the whole thing crashes probably because the

Dynamically skip pages in ViewPager

≡放荡痞女 提交于 2019-12-05 16:04:07
问题 I got a ViewPager which holds Fragment s via FragmentStatePagerAdapter . Let's say the pager initially holds the following pages ( Fragment s): A - B - C - D When the user swipes, he can move from A to B , B to C etc. But there are cases when the user changes some options on the A page, he can move not to B , but C : A - C - D Then the user goes back to A , modifies something and that re-enables B : A - B - C - D How can i achieve this very dynamic behavior? I cannot add Fragment s any time

How to extract objects from ListView - getItemAtPosition won't work

核能气质少年 提交于 2019-12-05 08:09:07
I've a custom adapter implemented for my ListView . How do I extract objects from a particular list item. Here's how my custom adapter looks: MyCustomAdapter.java public class MyCustomAdapter extends ArrayAdapter<DashboardBean> { Context context; int layoutResourceId; DashboardBean currentMRB; Vector<DashboardBean> data; public MyCustomAdapter(Context context, int layoutResourceId, Vector<DashboardBean> data) { super(context,layoutResourceId,data); this.layoutResourceId = layoutResourceId; this.context=context; this.data = data; } @Override public View getView(int position, View convertView,

Force RecyclerView to call onCreateViewHolder

限于喜欢 提交于 2019-12-05 07:09:35
I have a RecyclerView that can show items as list, small grids or large grid and this can be change at runtime. Depending on what style user chooses i inflate different layout in onCreateViewHolder . I also use layoutManger.setSpanSizeLookUp() to switch between styles. My code looks like this layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { if(showType == ProductAdapter.SHOW_TYPE_SMALL_GRID) return 1; else return columnCount; //show one item per row } }); @Override public void onClick(View v) { if(showType ==

Better to recreate listview adapter or to clear and repopulate?

拜拜、爱过 提交于 2019-12-05 06:32:44
If I have a ListView with a CustomAdapter and let's say I have this refresh() method that refreshes the list with new results, should I: Call new CustomAdapter(...) upon initialization, and every time I call refresh() , I use adapter.clear() and adapter.add(...) Call new CustomAdapter(...) every time I call refresh() Basically, I'm asking, is it better to recreate an adapter everytime I load new results or is it better to clear the results in existing adapter and add the entire list to it? It is definitely better to call notifyDataSetChanged() on the original adapter than setting a new one.

Set ListView Height dynamically based on multiline textview inside it

半城伤御伤魂 提交于 2019-12-05 05:55:35
I am using a base adapter to set data in a listview dynamically. I tried to set listview height dynamically. It works perfectly if the textview inside it is single line. However if the textview is multiline, the height is not set properly. The height is set considering single line textview only. How can I set correctly set the height of listview items containing multiline textview. Here's the code: Fragment code: ListView mlistNews=(ListView)rootView.findViewById(R.id.news_listView); mlistNews.setAdapter(new NewsAdapter(getActivity(),params_news)); Utils.setListViewHeightBasedOnItems(mlistNews

Do I need multiple viewHolders for ExpandableListView?

隐身守侯 提交于 2019-12-05 05:54:36
问题 Am I using this viewholder wrong? I'm getting an NPE on line 165. Is there an obvious reason why that I'm missing? Do I need a group viewholder and a child viewholder if I'm using expandablelistview? I marked line 165 to try to make it easier on the eyes. Thanks a lot my expandablelistview that's getting the NPE: public class MyExpandableListAdapter extends BaseExpandableListAdapter { private Context mContext; private ArrayList<ContactNameItems> mListDataHeader; private ArrayList<Boolean>