我在使用自定义适配器将视图返回到列表视图时遇到问题.这是我在扩展Fragment的主类中所拥有的.
public VIEw onCreateVIEw(LayoutInflater inflater, VIEwGroup container, Bundle savedInstanceState) { VIEw vIEw = inflater.inflate(R.layout.fragment_perfil_config, container, false); listadapter adapter = new PerfilOptionsAdapter(ListOptions(), getActivity()); ListPerfilConfigOptions = (ListVIEw) getActivity().findVIEwByID(R.ID.ListEvents); ListPerfilConfigOptions.setAdapter(adapter); return vIEw;}
这是名为PerfilOptionsAdapter的自定义适配器的功能:
public class PerfilOptionsAdapter extends BaseAdapter { private Activity activity; private List<PerfilConfigOption> options; private DateHelper dateHelper = new DateHelper(); public PerfilOptionsAdapter(List<PerfilConfigOption> options, Activity activity) { this.options = options; this.activity = activity; } @OverrIDe public int getCount() { return options.size(); } @OverrIDe public Object getItem(int position) { return options.get(position); } @OverrIDe public long getItemID(int position) { PerfilConfigOption option = options.get(position); return option.getoptionID(); } @OverrIDe public VIEw getVIEw(int position, VIEw convertVIEw, VIEwGroup parent) { LayoutInflater inflater = activity.getLayoutInflater(); VIEw line = inflater.inflate(R.layout.perfilconfigoptions_List , null); PerfilConfigOption option = options.get(position); TextVIEw optionname = (TextVIEw) line.findVIEwByID(R.ID.perfilConfigOptionname); optionname.setText(option.getoptionname()); //ImageVIEw photo = (ImageVIEw) line.findVIEwByID(R.ID.perfilConfigOptionImage); //photo.setimageBitmap(option.getoptionImage()); return line; }}
Logcat响应:
05-07 19:50:07.677 1730-1730/com.cupdev.voucomo E/AndroIDRuntime﹕ FATAL EXCEPTION: main Process: com.cupdev.voucomo, PID: 1730 java.lang.NullPointerException at com.cupdev.voucomo.Fragments.PerfilConfigFragment.onCreateVIEw(PerfilConfigFragment.java:37) at androID.app.Fragment.performCreateVIEw(Fragment.java:1700) at androID.app.FragmentManagerImpl.movetoState(FragmentManager.java:890) at androID.app.FragmentManagerImpl.movetoState(FragmentManager.java:1062) at androID.app.BackStackRecord.run(BackStackRecord.java:684) at androID.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447) at androID.app.FragmentManagerImpl.run(FragmentManager.java:443) at androID.os.Handler.handleCallback(Handler.java:733) at androID.os.Handler.dispatchMessage(Handler.java:95) at androID.os.Looper.loop(Looper.java:136) at androID.app.ActivityThread.main(ActivityThread.java:5017) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method)
我不确定为什么该适配器根本不返回任何视图?我已经尝试过使用具有相同数据的SimpleAdapter来工作.我需要创建一个自定义适配器来处理图像数据.
任何帮助将不胜感激.谢谢
解决方法:
我猜您正在尝试查找ListPerfilConfigOptions而不是它在哪里:
试试这个代码:
ListPerfilConfigOptions =(ListVIEw)vIEw.findVIEwByID(R.ID.ListEvents);
总结以上是内存溢出为你收集整理的Android自定义适配器-不会返回视图吗?全部内容,希望文章能够帮你解决Android自定义适配器-不会返回视图吗?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)