adapter

Android: notifyDataSetChanged(); not working

夙愿已清 提交于 2019-11-26 08:24:40
问题 I have a database in a server and from a Tablet I take some values from one table in the database. I load this information correctly into a list but I would like to know why when there is a change, nothing happens even if I use notifyDataSetChanged(); . I must say that for loading the loading data y use the AsyncTaskClass So, my problem is that I don\'t know if use the notifyDataSetChanged(); method correctly ,because if there\'s is a change I would like to refresh the image. Here is some

When do you use the Bridge Pattern? How is it different from Adapter pattern?

白昼怎懂夜的黑 提交于 2019-11-26 04:58:00
问题 Has anyone ever used the Bridge Pattern in a real world application? If so, how did you use it? Is it me, or is it just the Adaptor Pattern with a little dependency injection thrown into the mix? Does it really deserve its own pattern? 回答1: A classic example of the Bridge pattern is used in the definition of shapes in an UI environment (see the Bridge pattern Wikipedia entry). The Bridge pattern is a composite of the Template and Strategy patterns. It is a common view some aspects of the

Call Activity method from adapter

狂风中的少年 提交于 2019-11-26 03:29:10
问题 Is it possible to call method that is defined in Activity from ListAdapter ? (I want to make a Button in list\'s row and when this button is clicked, it should perform the method, that is defined in corresponding Activity. I tried to set onClickListener in my ListAdapter but I don\'t know how to call this method, what\'s its path...) when I used Activity.this.method() I get the following error: No enclosing instance of the type Activity is accessible in scope Any Idea ? 回答1: Yes you can. In

AlphabetIndexer with Custom Adapter managed by LoaderManager

不羁的心 提交于 2019-11-26 02:23:08
问题 I am trying to implement AlphabetIndexer with Custom Adapter like this AlphabetIndexer with Custom Adapter My class ContactsCursorAdapter extends SimpleCursorAdapter and implements SectionIndexer and I am using a LoaderManager to manage my adapter\'s cursor so i have overridden the swapCursor() method like the second answer to the example above indicates. public class ContactsCursorAdapter extends SimpleCursorAdapter implements SectionIndexer{ private LayoutInflater mInflater; private Context

How to set selected item of Spinner by value, not by position?

僤鯓⒐⒋嵵緔 提交于 2019-11-26 01:04:10
问题 I have a update view, where I need to preselect the value stored in database for a Spinner. I was having in mind something like this, but the Adapter has no indexOf method, so I am stuck. void setSpinner(String value) { int pos = getSpinnerField().getAdapter().indexOf(value); getSpinnerField().setSelection(pos); } 回答1: Suppose your Spinner is named mSpinner , and it contains as one of its choices: "some value". To find and compare the position of "some value" in the Spinner use this: String

Android: How to bind spinner to custom object list?

丶灬走出姿态 提交于 2019-11-26 00:46:17
问题 In the user interface there has to be a spinner which contains some names (the names are visible) and each name has its own ID (the IDs are not equal to display sequence). When the user selects the name from the list the variable currentID has to be changed. The application contains the ArrayList Where User is an object with ID and name: public class User{ public int ID; public String name; } What I don\'t know is how to create a spinner which displays the list of user\'s names and bind

Android_适配器(adapter)之SimpleAdapter

主宰稳场 提交于 2019-11-26 00:44:48
概述 SimpleAdapter是一种 简单的适配器,将 静态数据映射到布局xml对应的视图 上。它也是BaseAdapter的子类。 SimpleAdapter数据映射的组件有3类(从官网api或SimpleAdapter源码中的bindView方法中都能看出来): Checkable(e.g. CheckBox), TextView, ImageView。 下面的例子中就包含了这3类 构造说明 SimpleAdapter只有一个构造方法: SimpleAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) context :上下文 data :数据源,一个包含Map的数据集合 resource :item的布局文件 from :数据来源的key的数组,与data的Map里的key对应 to : from中的每一项数据源 对应到的 item布局中对应组件的 id。 四个参数的关系及表明了这种数据映射到布局的关系(如下绘制的简单示意图) :data是数据源,包含所有数据,data中的每一项 是一个map;from是数据源中map中的key数组;to是item布局要填充的组件id的数组(这里的组件只能是上面提到的3种)。

Android, ListView IllegalStateException: “The content of the adapter has changed but ListView did not receive a notification”

半腔热情 提交于 2019-11-26 00:20:31
问题 What I want to do : run a background thread which calculates ListView contents and update ListView partially, while results are calculated. What I know I have to avoid : I cannot mess with ListAdapter contents from background thread, so I inherited AsyncTask and publish result (add entries to adapter) from onProgressUpdate. My Adapter uses ArrayList of result objects, all operations on those arraylists are synchronized. Research of other people : there is very valuable data here. I also

How to set selected item of Spinner by value, not by position?

徘徊边缘 提交于 2019-11-25 23:32:40
I have a update view, where I need to preselect the value stored in database for a Spinner. I was having in mind something like this, but the Adapter has no indexOf method, so I am stuck. void setSpinner(String value) { int pos = getSpinnerField().getAdapter().indexOf(value); getSpinnerField().setSelection(pos); } Merrill Suppose your Spinner is named mSpinner , and it contains as one of its choices: "some value". To find and compare the position of "some value" in the Spinner use this: String compareValue = "some value"; ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource

Android中适配器的notifyDataSetChanged()为何有时不刷新

风流意气都作罢 提交于 2019-11-25 22:58:15
学过Android开发的人都知道,ListView控件在开发中经常遇到,并且ListView通常结合Adapter适配器来进行数据显示和数据更新操作。姑且假设数据存储在名为dataList的成员变量中。数据操作无非是增加数据、删除数据这两种主要的操作,而当数据有所变化时,为了及时向用户提供更新后的数据,我们知道需要在数据更新后调用适配器的notifyDataSetChanged()方法,来显示更新后的数据。殊不知,该方法并非百试不爽,在此我们便来讨论下具体的原因,其实本质是关注内存的分配情况。 先来看几段代码。 代码段1(某Activity中): private List<Map<String,String>> dataList; private ListView listView; private ListAdapter adapter; listView = findViewById(R.id.mancard); adapter = new ListAdapter(this, dataList); listView.setAdapter(adapter); 上述代码是把Adapter适配器和ListView控件进行绑定。 代码段2(ListAdapter中的部分代码): public class ListAdapter extends BaseAdapter{ private