安卓:自定义ListAdapter扩大对应用程序启动BaseAdapter崩溃 [英] Android: Custom ListAdapter extending BaseAdapter crashes on application launch
本文介绍了安卓:自定义ListAdapter扩大对应用程序启动BaseAdapter崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
数据被从本地数据库拉出,然后被映射使用一个光标。自定义适配器显示的数据类似于一个ListView。作为项目被添加/从DB中删除,适配器是应该进行刷新。尝试以下解决方法崩溃在启动该应用程序。有什么建议?
在此先感谢, -D
@覆盖
公共查看getView(INT位置,查看convertView,ViewGroup中父){
视图V = convertView;
ViewGroup中P =父母;
如果(V == NULL){
LayoutInflater VI =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ν= vi.inflate(R.layout.items_row,p)的;
}
INT大小= mAdapter.getCount();
Log.d(TAG,位置+位置+尺寸+大小);
如果(大小!= 0){
如果(位置及所述;大小)返回mAdapter.getView(位置,V,P);
Log.d(TAG,位置+位置+尺寸+大小);
}
返回null;
}
例外:
03-23 00:14:10.392:ERROR / AndroidRuntime(718):java.lang.UnsupportedOperationException:addView(查看,的LayoutParams)不支持适配器视图
03-23 00:14:10.392:ERROR / AndroidRuntime(718):在android.widget.AdapterView.addView(AdapterView.java:461)
03-23 00:14:10.392:ERROR / AndroidRuntime(718):在android.view.LayoutInflater.inflate(LayoutInflater.java:415)
03-23 00:14:10.392:ERROR / AndroidRuntime(718):在android.view.LayoutInflater.inflate(LayoutInflater.java:320)
03-23 00:14:10.392:ERROR / AndroidRuntime(718):在android.view.LayoutInflater.inflate(LayoutInflater.java:276)
03-23 00:14:10.392:ERROR / AndroidRuntime(718):在com.xyz.abc.CustomSeparatedListAdapter.getView(CustomSeparatedListAdapter.java:90)
...
解决方案
V = vi.inflate(R.layout.items_row,P);
添加假
第三个参数设置为呼叫,我认为你的问题就会迎刃而解。呼叫应该成为:
V = vi.inflate(R.layout.items_row,P,假);
Data being pulled from a local DB, then mapped using a cursor. Custom Adapter displays data similar to a ListView. As items are added/deleted from the DB, the adapter is supposed to refresh. The solution attempted below crashes the application at launch. Any suggestions?
Thanks in advance, -D
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
ViewGroup p = parent;
if (v == null) {
LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.items_row, p);
}
int size = mAdapter.getCount();
Log.d(TAG, "position " + position + " Size " + size);
if(size != 0){
if(position < size) return mAdapter.getView(position, v, p);
Log.d(TAG, "-position " + position + " Size " + size);
}
return null;
}
Exception:
03-23 00:14:10.392: ERROR/AndroidRuntime(718): java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView
03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.widget.AdapterView.addView(AdapterView.java:461)
03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
03-23 00:14:10.392: ERROR/AndroidRuntime(718): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
03-23 00:14:10.392: ERROR/AndroidRuntime(718): at com.xyz.abc.CustomSeparatedListAdapter.getView(CustomSeparatedListAdapter.java:90)
...
解决方案
v = vi.inflate(R.layout.items_row, p);
Add a false
third parameter to that call, and I think your problem will go away. The call should become:
v = vi.inflate(R.layout.items_row, p, false);
这篇关于安卓:自定义ListAdapter扩大对应用程序启动BaseAdapter崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文