listview中的android不一致多个布局通胀

时间:2013-07-04 13:33:51

标签: android listview pull-to-refresh

我使用PulltoRefresh listview,我使用3种布局。 1.游戏布局(当链接列表项以#34; gm&#34开头时应该膨胀;) 2. Adlayout(当链接列表项以&#34开头时应该膨胀;广告") 3.Normal Listview布局(在所有其他情况下) 这是代码

mListItems = new LinkedList<String>();
mListItems.add(0,"hi1");
        mListItems.add(1,"hi2");
        mListItems.add(2,"gm");
        mListItems.add(3,"hi3");
        mListItems.add(4,"ad");
        mListItems.add(5,"hi4");


((PullToRefreshListView) getListView())
                .setOnRefreshListener(new OnRefreshListener() {
                    @Override
                    public void onRefresh() {
                        // Do work to refresh the list here.
                        new GetDataTask().execute();
                    }
                });

private class GetDataTask extends AsyncTask<Void, Void, String[]> {

        @Override
        protected String[] doInBackground(Void... params) {
            // Simulates a background job.
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                ;
            }
            return mStrings;
        }

        @Override
        protected void onPostExecute(String[] result) {

            // mListItems.addFirst("Added after refresh...");
//          parseJson("IndigoFM_06212013.json");
            mListItems.addFirst("how are you");
            mListItems.addFirst("ad");
            mListItems.addFirst("gm");
            mListItems.addFirst("the end");

            // Call onRefreshComplete when the list has been refreshed.
            ((PullToRefreshListView) getListView()).onRefreshComplete();

            super.onPostExecute(result);
        }
    }

这是适配器代码

private class basicListAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            // TODO Auto-generated method stub

            return mListItems.size();
        }

        @Override
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return mListItems.get(position);
        }

        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
            View v = convertView;
            if (v == null) {
                LayoutInflater inflater = LayoutInflater
                        .from(getApplicationContext());

                if ((mListItems.get(position).startsWith("gm"))) {

                    v = inflater.inflate(R.layout.gaminglayout, null);
                } else if ((mListItems.get(position).startsWith("ad"))) {

                    v = inflater.inflate(R.layout.adlayout, null);
                } else if(!(mListItems.get(position).startsWith("gm")) && !(mListItems.get(position).startsWith("ad")))  {
                    v = inflater.inflate(R.layout.listinflate, null);
                }
                viewHolder holder = new viewHolder();
                adViewHolder adHolder = new adViewHolder();
                gamingViewHolder gamingHolder = new gamingViewHolder();
                 if ((mListItems.get(position).startsWith("ad"))) {
                    adHolder.adDetails = (TextView) v.findViewById(R.id.adText);
                    v.setTag(adHolder);
                } else if ((mListItems.get(position).startsWith("gm"))) {
                    gamingHolder.gamingButton = (Button) v
                            .findViewById(R.id.gamingButton);
                    gamingHolder.gamingButton .setOnClickListener(mOngamingButtonClickListener);
                    v.setTag(gamingHolder);
                }else  if(!(mListItems.get(position).startsWith("gm")) && !(mListItems.get(position).startsWith("ad"))){
                    holder.rjName = (TextView) v.findViewById(R.id.rjName);
                    holder.textViewName = (TextView) v
                            .findViewById(R.id.textViewName);
                    holder.likeLayout = (LinearLayout) v
                            .findViewById(R.id.likeLayout);
                    holder.commentLayout = (LinearLayout) v
                            .findViewById(R.id.commentLayout);
                    holder.likeLayout
                            .setOnClickListener(mOnLikeLayoutClickListener);
                    holder.commentLayout
                            .setOnClickListener(mOnCommentLayoutClickListener);
                    v.setTag(holder);
                } 
            }

            if (mListItems.get(position) != null) {

                // if(!(mListItems.get(position).startsWith("1"))){
                if (!(v.getTag() instanceof adViewHolder)) {
                    if(!(v.getTag() instanceof gamingViewHolder)){
                    viewHolder holder = (viewHolder) v.getTag();
                    holder.textViewName.setText(mListItems.get(position));
                    }
                }
            }

            return v;

        }

    }

现在的问题是,在我拉动刷新之后,以&#34; gm&#34;开头的条目正常列表视图布局中显示但不是游戏布局。 在某种程度上说不正确的布局正在膨胀

0 个答案:

没有答案