getChildAt(0)为具有多个视图的Listview返回null

时间:2013-09-24 10:25:32

标签: android listview android-listview

我有Listview多个视图。请使用以下代码设置第二项的选择。但视图始终为null。请帮助我。由于字符限制我无法附加用于列表视图的布局

View view = ListView.getChildAt(0);
            int top = (view == null) ? 0 : view.getTop();
            // restore list
            ListView.setSelectionFromTop(ListView.getFirstVisiblePosition() + 1, top);

适配器

@Override
public int getItemViewType(int position) {

    if (Details.get(position).getView_type() == 1)
        return ITEM_TYPE_ONE;
    else if (Details.get(position).getView_type() == 0)
        return ITEM_TYPE_THREE;
    else
        return ITEM_TYPE_TWO;

}

@Override
public int getViewTypeCount() {
    return 3;
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    vi = convertView;
    int type = getItemViewType(position);
    if (convertView == null) {
        holder = new ViewHolder();
        switch (type) {
        case ITEM_TYPE_ONE:
            vi = inflater.inflate(R.layout.feed_detail_list_item_selected,
                    null);
            holder.name = (TextView) vi
                    .findViewById(R.id.list_item_name_txt);
            holder.profilepic = (ImageView) vi
                    .findViewById(R.id.list_item_profile_img);

            break;
        case ITEM_TYPE_TWO:
            vi = inflater.inflate(R.layout.listlastrow, null);
            holder.name = (TextView) vi.findViewById(R.id.msg);
            break;
        case ITEM_TYPE_THREE:
            vi = inflater
                    .inflate(R.layout.feed_details_parent_layout, null);
            holder.name = (TextView) vi.findViewById(R.id.ownerName);
            holder.profilepic = (ImageView) vi
                    .findViewById(R.id.thumb_image);

            holder.VoiceBar = (SeekBar) vi
                    .findViewById(R.id.message_seekbar);
            holder.voice_bar_layout = (LinearLayout) vi
                    .findViewById(R.id.seekbar_layout);


            break;
        }
        vi.setTag(holder);
    } else {
        holder = (ViewHolder) vi.getTag();

    }
    if (type == ITEM_TYPE_TWO) {

        holder.name.setTypeface(tfNormal);
        ((LinearLayout) vi.findViewById(R.id.ll))
                .setBackgroundColor(mContext.getResources().getColor(
                        R.color.white));
        if (Details.size() == 2) {
            holder.name.setVisibility(View.VISIBLE);
            holder.name.setText(mContext.getResources().getString(
                    R.string.no_replies));
        } else {
            holder.name.setVisibility(View.GONE);

        }
    }

    }
    return vi;
}

0 个答案:

没有答案