adapter

Android: How to make an adapter with stable ids?

自闭症网瘾萝莉.ら 提交于 2019-11-30 23:20:09
问题 I've made my own custom adapter extended from BaseAdapter to show a listview and so on... I want it to support single and multi selection, so it must have stable ids. I've checked with the ADAPTER.hasStableIds() and the result is false. I've overrided this method to do try to get stables ids with no luck. public long getItemId(int position) { return (long) getItem(position).hashCode(); } Any idea how to make it? thanks! 回答1: Override hasStableIds to return true. Also the data on your adapter

Android Radio buttons in a custom listview changes its state when we scroll the list

房东的猫 提交于 2019-11-30 21:27:27
I am a beginner and facing a problem where I am creating a ListView with two RadioButton s and a TextView . Everything goes fine, but when I set RadioButton s and scroll it, the values of previous RadioButton s change their values or lose their state dramatically. I am trying to solve this problem for long time. What changes should I make to overcome this problem? MainActivity.java public class MainActivity extends Activity { private ListView listView1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Option

Asynchronous download of Bitmaps in an Adapter, with emphasis on Bitmap.recycle()

怎甘沉沦 提交于 2019-11-30 20:16:21
Could someone tell me how to make a good mechanism for async. download of images for use in a ListView/GridView? There are many suggestions , but each only considers a small subset of the typical requirements. Below I've listed some reasonable factors (requirements or things to take into account) that I, and my collegues, are unable to satisfy at once. I am not asking for code (though it would be welcome), just an approach that manages the Bitmaps as described. No duplication of downloaders or Bitmaps Canceling downloads/assigning of images that would no longer be needed, or are likely to be

android listview displays false data after scrolling (custom adapter)

只愿长相守 提交于 2019-11-30 19:53:45
I've got a strange problem that drives me crazy. In my android application I customized my own adapter that extends from ArrayAdapter. The items of the ListView to which I added my adapter can either be labeled-text (not editable), editable text or a spinner. The crazy stuff is: when I scroll the ListView, there are two problems: (1) the (selected) value that is shown in the spinner items changes sometimes although I only scrolled!! when I click on the spinner, the old selected value is still shown (the one, that should be shown by the spinner) (2) the order of the ListViewItems changes when I

Cannot understand NullPointerException with custom adapter

早过忘川 提交于 2019-11-30 19:47:07
问题 I am trying to create a list view which as TextView that can display html content , an WebView and other basic TextViews.I tried to extend SimpleAdapter but i struck with the problem ,I will be glad if someone can point out the mistake i am doing. In onCreate method ArrayList<HashMap<String, String>> mylist= resultfromXmlparser(); adap = new MyAdapter(TourLandingPage.this, mylist, R.layout.row, new String[] {"Name", "desc","Duration","Price","imgurl"}, new int[] {R.id.productname,R.id.des,R

how to generate dynamic RadioButton with a radiongroup in adapterView?

空扰寡人 提交于 2019-11-30 19:27:17
问题 I have a Dynamic list.. I want to show that list in adapter view with radio buttons. in one group. I used: public class Type2Adapter extends BaseAdapter{ Context context; LayoutInflater inflater; ArrayList<QueOption> oplist; String list1; int count; RadioGroup radiogroup; String dot,more; public Type2Adapter(Context context,ArrayList<QueOption> arrayList){ this.context = context; inflater = LayoutInflater.from(context); oplist = arrayList; count = oplist.size(); if(count>=1){ count = oplist

Custom ViewPager

允我心安 提交于 2019-11-30 18:15:35
问题 How can i create a customized ViewPager ? To instantiate a page in the ViewPager it's something like this : public Object instantiateItem(View collection, int position) { TextView tv = new TextView(cxt); tv.setText("Bonjour PAUG " + position); tv.setTextColor(Color.WHITE); tv.setTextSize(30); ((ViewPager) collection).addView(tv,0); return tv; } is there a way to inflate like this in a Class extended from an Adapter : public View getView(int position, View convertView, ViewGroup parent) { View

Why this Error occurred? java.lang.RuntimeException: ImageLoader must be init with configuration before using

别来无恙 提交于 2019-11-30 17:47:31
I have downloaded one ImageDownloader code from gitHub( from Here ) Now when I am trying to download the image from my webservice I am getting this Runtime Exception "ImageLoader must be init with configuration before using". I am not able to figure it out. And this my adapter: public class CustomAdapter extends BaseAdapter { private Context context; private ArrayList<String> logo_URL; private ListContent listContent; private ArrayList< TeamDataClass> teamdata = null; private ArrayList<EventDataClass> eventdata = null; private DisplayImageOptions options; private ImageLoader imageLoader;

How to sort RecyclerView item in android

我与影子孤独终老i 提交于 2019-11-30 17:46:25
I'm working on a android chatting application. When I called my api it returns me the chat list sorted by a user_id. But what I need to do is serialized by message_id as I want to show last message first.Here is my onBindViewHolder method in which i get the values. public void onBindViewHolder(final MyAdapter_HomeViewHolder holder, final int position) { holder.userNameTV.setText(data.get(position).getUserInfo().getFullName()); holder.msgBodyTV.setText(data.get(position).getBody()); holder.originator_iD.setText(data.get(position).getUserInfo().getId().toString()); //message ID. I need to

Treat Enumeration<T> as Iterator<T>

假装没事ソ 提交于 2019-11-30 17:28:22
I have a class that implements the Enumeration<T> interface, but Java's foreach loop requires the Iterator<T> interface. Is there an Enumeration to Iterator Adapter in Java's standard library? Bozho You need a so called "Adapter", to adapt the Enumeration to the otherwise incompatible Iterator . Apache commons-collections has EnumerationIterator . The usage is: Iterator iterator = new EnumerationIterator(enumeration); If you just want something to iterate over in a for-each loop (so an Iterable and not only an Iterator), there's always java.util.Collections.list(Enumeration<T> e) (without