android-adapter

Best way to update data with a RecyclerView adapter [duplicate]

耗尽温柔 提交于 2019-11-26 09:24:22
问题 This question already has an answer here: How to update RecyclerView Adapter Data? 12 answers When I have to use a classic adapter with a ListView, I update my data in the ListView like this: myAdapter.swapArray(data); public swapArray(List<Data> data) { clear(); addAll(data); notifyDataSetChanged(); } I would like to know what is the best practice for a RecyclerView. Because in a RecyclerView adapter you can\'t do a clear and addAll as in ListView . So I tried just with a

Android: how to refresh ListView contents?

谁都会走 提交于 2019-11-26 08:04:47
问题 My ListView is using an extension of BaseAdapter , I can not get it to refresh properly. When I refresh, it appears that the old data draws on top of the new data, until a scroll event happens. The old rows draw on top of the new rows, but the old rows disappear when I start scrolling. I have tried calling invalidateViews() , notifyDataSetChanged() , and notifyDataSetInvalidated() . My code looks something like: private void updateData() { List<DataItems> newList = getNewList(); MyAdapter

No adapter attached; skipping layout [duplicate]

吃可爱长大的小学妹 提交于 2019-11-26 07:48:06
问题 This question already has an answer here: recyclerview No adapter attached; skipping layout 30 answers logcat error : No adapter attached; skipping layout I changed the context argument with getActivity(), but the app is still not running. public class FragmentActivity extends Fragment { private RecyclerView mRecyclerView; private CountryAdapter mAdapter; private LinearLayoutManager layoutManager; public FragmentActivity(){} @Override public View onCreateView(LayoutInflater inflater,

Android - Implementing search filter to a RecyclerView

这一生的挚爱 提交于 2019-11-26 05:29:02
问题 I need to implement a search feature based on an EditText to my RecyclerView . The list must be filtered while typing. Here\'s the code : DisplayAdapter.java this is the adapter public class DisplayAdapter extends RecyclerView.Adapter<DisplayAdapter.MyViewHolder>{ private List<DataHolder> displayedList; public class MyViewHolder extends RecyclerView.ViewHolder{ public TextView english_d; public MyViewHolder(View view){ super(view); english_d = (TextView) view.findViewById(R.id.engword); } }

Using AsyncTask to load Images in ListView

不打扰是莪最后的温柔 提交于 2019-11-26 02:36:10
问题 I have one ListView which can hold an image. It depends if image exists or not in SDCARD. Here my example code: public class MainActivity extends Activity { ListView mListView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mListView = new ListView(this); setContentView(mListView); String[] arr = new String[] { \"/example/images/1.jpg\", \"/example/images/2.jpg\", \"/example/images/3.jpg\", \"/example/images/4.jpg\", \"/example/images/5.jpg\

Update data in ListFragment as part of ViewPager

做~自己de王妃 提交于 2019-11-26 01:23:28
问题 I\'m using the v4 compatibility ViewPager in Android. My FragmentActivity has a bunch of data which is to be displayed in different ways on different pages in my ViewPager. So far I just have 3 instances of the same ListFragment, but in the future I will have 3 instances of different ListFragments. The ViewPager is on a vertical phone screen, the lists are not side-by-side. Now a button on the ListFragment starts an separate full-page activity (via the FragmentActivity), which returns and

android - listview get item view by position

痞子三分冷 提交于 2019-11-26 00:33:11
问题 I have listview with custom adapter (base adapter). I want to get view from listview by position. I tried mListView.getChildAt(position) , but it is not working. How can i get item view by position? 回答1: Use this : public View getViewByPosition(int pos, ListView listView) { final int firstListItemPosition = listView.getFirstVisiblePosition(); final int lastListItemPosition = firstListItemPosition + listView.getChildCount() - 1; if (pos < firstListItemPosition || pos > lastListItemPosition ) {

How to customize listview using baseadapter

折月煮酒 提交于 2019-11-25 23:47:10
问题 I wanna create a customized ListView like this: I think that I have to use BaseAdapter but I have no idea about it. 回答1: main.xml: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin"

Custom Adapter getView() method is not called

家住魔仙堡 提交于 2019-11-25 23:28:18
问题 Here is the code of the fragment in which I am setting a custom adapter to the list. There no errors but the ListView is empty. I have implemented getCount() which returns right number of items in my ArrayList. I don\'t see (\"Inside\", \"GetView\") in the logcat Fragment public class ServiceCarListFragment extends Fragment { private String url; private ArrayList<CarDetail> carDetailList = new ArrayList<CarDetail>(); private CarListAdapter adapter; private ListView mList; @Override public