adapter

can we call startActivityForResult from adapter?

守給你的承諾、 提交于 2019-12-20 10:18:21
问题 is it possible to have method onActivityResume within adapter & call startActivityForResult ? 回答1: Yes. Just pass the context of the activity to the adapter in the adapter's constructor (here stored as mContext). In getView, just call ((Activity) mContext).startActivityForResult(intent,REQUEST_FOR_ACTIVITY_CODE); 回答2: Not necessarily pass to pass context in adapter's constructor. You can get context from parent ViewGroup. Sample for RecyclerView adapter: Context mContext; @Override public

android listviews: header and footer views

可紊 提交于 2019-12-20 09:19:32
问题 In my ListActivity, I need header and footer views (on the top and bottom of the list) to be used as previous page and next page buttons on my list, respectively, because I want to display only 20 items at a time. I set my header and foot views by doing: getListView().addHeaderView(myHeaderView); getListView().addFooterView(myFooterView); setListAdapter(adapter); This works fine, but I need to dynamically remove and add these header and footer views, because some pages of my list may not have

ListView回收机制相关分析

左心房为你撑大大i 提交于 2019-12-20 09:10:42
最初的分析文档为word,该文档是直接从word文档发布,布局未做详细调整,凑合看吧。 所用源码版本为最新的Android 4.4.2(API 19)。更新中…… ListView 回收机制相关分析 1 1. ListView 结构关系 1 2. RecycleBin 类解析 3 2.1 RecycleBin 变量 4 2.2 RecycleBin 方法 4 3. RecycleBin 的调用和关键方法 7 3.1 ListView 7 3.1.1 layoutChildren 7 3.1.2 makeAndAddView 8 3.1.3 setupChild 9 3.1.4 setAdapter 9 3.1.5 scrollListItemsBy 10 3.2 AbsListView 12 3.2.1 obtainView 12 3.2.2 trackMotionScroll 14 4. 用到的关键类 15 4.1 ViewType 的使用 15 4.2 TransientStateView 17 ListView结构关系 首先理清listview的层级关系, 使用Google Online Draw 画出继承关系图如下: 图中单独画出Scrollview是为了说明该ViewGroup并没有自带回收机制,如果要是Scrollview显示大量view,需要手动做处理。

What is the difference between the Facade and Adapter Pattern?

血红的双手。 提交于 2019-12-20 08:08:58
问题 I've been reading both definitions and they seem quite the same. Could anyone point out what are their differences? Thanks 回答1: The Facade Pattern wiki page has a brief note about this. "An Adapter is used when the wrapper must respect a particular interface and must support a polymorphic behavior. On the other hand, a facade is used when one wants an easier or simpler interface to work with." I heard an analogy that you should think of your universal remote control that you've set up to work

Dynamic list view with a dynamic adapter

假如想象 提交于 2019-12-20 07:38:41
问题 I want to create a dynamic listview which adds dynamic elements on scrolling to the end of the initial list. New items should be added everytime the scroll position reaches the end of previous list. How can I achieve this? Thank you. 回答1: you need to add a scroll listener and override the onscroll() 来源: https://stackoverflow.com/questions/9454170/dynamic-list-view-with-a-dynamic-adapter

FATAL EXCEPTION: main android java

时光怂恿深爱的人放手 提交于 2019-12-20 07:33:15
问题 I want to populate listview through adapter using array like below: public class ChildActivity extends ActionBarActivity implements GetChildList { private ListView lv_child; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_child); List<String> array = new ArrayList<String>(); // for e.g array ["num1", "num2"] lv_child = (ListView)findViewById(R.id.lv_child); ArrayAdapter<String> adapterChild = new ArrayAdapter

Android App crashes after Scrolling down ListView

我的梦境 提交于 2019-12-20 06:27:21
问题 I have a listView, everything's working fine whan I don't have too much items on it.. When the list of items is long when I scroll down it crashes at a certain point... This is my adapter code : public class SearchListViewAdapter extends BaseAdapter { private LayoutInflater layoutInflater; private JsonArray searchResults; public SearchListViewAdapter(Context context, JsonArray searchResults) { this.searchResults = searchResults; layoutInflater = LayoutInflater.from(context); } @Override

Access fragment from adapter

て烟熏妆下的殇ゞ 提交于 2019-12-20 01:35:20
问题 The idea is i have a listview where each item is a product, when I click in the item, I need to go to another Fragment from the click which is inside the adapter of the listview. My adapter is: package info.android.adapter; import info.android.ProductFragment; import info.android.R; import java.util.ArrayList; import android.app.Activity; import android.app.Fragment; import android.app.FragmentTransaction; import android.content.Context; import android.view.LayoutInflater; import android.view

Access fragment from adapter

[亡魂溺海] 提交于 2019-12-20 01:34:46
问题 The idea is i have a listview where each item is a product, when I click in the item, I need to go to another Fragment from the click which is inside the adapter of the listview. My adapter is: package info.android.adapter; import info.android.ProductFragment; import info.android.R; import java.util.ArrayList; import android.app.Activity; import android.app.Fragment; import android.app.FragmentTransaction; import android.content.Context; import android.view.LayoutInflater; import android.view

Access fragment from adapter

半城伤御伤魂 提交于 2019-12-20 01:34:21
问题 The idea is i have a listview where each item is a product, when I click in the item, I need to go to another Fragment from the click which is inside the adapter of the listview. My adapter is: package info.android.adapter; import info.android.ProductFragment; import info.android.R; import java.util.ArrayList; import android.app.Activity; import android.app.Fragment; import android.app.FragmentTransaction; import android.content.Context; import android.view.LayoutInflater; import android.view