public EyediseasesFragment(file diseasesJsonfile) { this.diseasesJsonfile = diseasesJsonfile; mainUrl = Config.mainUrl;}@OverrIDepublic voID onActivityCreated(Bundle savedInstanceState) { // Todo auto-generated method stub super.onActivityCreated(savedInstanceState); diseasesList = new ArrayList<diseases>(); new LoadContent().execute();}@OverrIDepublic voID onAttach(Activity activity) { super.onAttach(activity); try { Listener = (MainFragmentController) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnArticleSelectedListener"); }}@OverrIDepublic voID onCreate(Bundle savedInstanceState) { // Todo auto-generated method stub super.onCreate(savedInstanceState);}@OverrIDepublic VIEw onCreateVIEw(LayoutInflater inflater,VIEwGroup container,Bundle savedInstanceState) { VIEw vIEw = inflater.inflate(R.layout.diseases,container,false); mList = (ListVIEw) vIEw.findVIEwByID(R.ID.diseases); return vIEw;}class diseasesAdapter extends BaseAdapter { LayoutInflater inflater; public diseasesAdapter() { inflater = (LayoutInflater) getActivity().getSystemService( Context.LAYOUT_INFLATER_SERVICE); } @OverrIDe public int getCount() { return diseasesList.size(); } @OverrIDe public diseases getItem(int arg0) { return diseasesList.get(arg0); } @OverrIDe public long getItemID(int arg0) { return arg0; } @OverrIDe public VIEw getVIEw(final int position,VIEw convertVIEw,VIEwGroup arg2) { final diseases item; VIEwHolder holder; if (convertVIEw == null) { holder = new VIEwHolder(); convertVIEw = inflater.inflate(R.layout.diseases_item,null); holder.Title = (TextVIEw) convertVIEw.findVIEwByID(R.ID.disease_item_header); convertVIEw.setTag(holder); } else { holder = (VIEwHolder) convertVIEw.getTag(); } item = getItem(position); holder.Title.setText(item.diseasename); convertVIEw.setLayoutParams(new ListVIEw.LayoutParams( LayoutParams.MATCH_PARENT,HelperStaticmethods.getDIP( getActivity(),50))); convertVIEw.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw arg0) { Listener.ondiseasItemClick(item); } }); return convertVIEw; }}class VIEwHolder { TextVIEw Title;}class LoadContent extends AsyncTask<VoID,VoID,VoID> { @OverrIDe protected VoID doInBackground(VoID... params) { setdiseasesinformation(getActivity()); return null; } @OverrIDe protected voID onPostExecute(VoID result) { super.onPostExecute(result); mList.setCachecolorHint(color.transparent); mList.setdivIDer(null); mList.setVerticalFadingEdgeEnabled(false); diseasesAdapter adapter = new diseasesAdapter(); mList.setAdapter(adapter); } @OverrIDe protected voID onPreExecute() { // Todo auto-generated method stub super.onPreExecute(); }}
编辑
将下面的代码移动到convertVIEw为Null的语句中解决了问题.
if (convertVIEw == null) { // ... after inflating the vIEw convertVIEw.setLayoutParams(new ListVIEw.LayoutParams( LayoutParams.MATCH_PARENT,HelperStaticmethods.getDIP(getActivity(),50)));}解决方法 你可以尝试移动代码吗?
convertVIEw.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw arg0) { Listener.ondiseasItemClick(item); } });
内
if (convertVIEw == null){.....}
确保监听器设置一次.
总结以上是内存溢出为你收集整理的ListView中的第一项在Android中无法正常工作全部内容,希望文章能够帮你解决ListView中的第一项在Android中无法正常工作所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)