在列表视图更改行的内容时,在视图的onClick [英] Change row content view when at onClick in listview

查看:188
本文介绍了在列表视图更改行的内容时,在视图的onClick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我用两个diferent布局(mycontentmtall或mycontenmotall)列表视图。我想(当我连续点击的对象选择了一个来自这两个新的布局,我创建(mycontentmtallexapand或mycontentmoallexpand)再次)来改变点击这两个布局。

我的脸在那里,当我在列表视图点击一个项目的问题,我没有看到布局的变化。

  @覆盖
            公共查看getView(最终诠释的立场,观点convertView,
                    父母的ViewGroup){                 最后ViewHolder持有人;
                // int型的= getItemViewType(位置);
                最后的消息消息=的getItem(位置);                如果(convertView == NULL){                    持有人=新ViewHolder();
                    //如果(类型== TYPE_MT){
                    如果(!message.getIsMO()){
                        convertView = mInflater.inflate(R.layout.mycontentmtall,
                                空值);
                        holder.body =(TextView中)convertView
                                .findViewById(R.id.bodyMT);
                        holder.date =(TextView中)convertView
                                .findViewById(R.id.dateMT);
                        holder.from =(TextView中)convertView
                                .findViewById(R.id.fromMT);
                        holder.status =(TextView中)convertView
                                .findViewById(R.id.statusMT);
                    }其他{
                        convertView = mInflater.inflate(R.layout.mycontentmoall,
                                空值);
                        holder.body =(TextView中)convertView
                                .findViewById(R.id.bodyMO);
                        holder.date =(TextView中)convertView
                                .findViewById(R.id.dateMO);
                        holder.from =(TextView中)convertView
                                .findViewById(R.id.fromMO);
                        holder.status =(TextView中)convertView
                                .findViewById(R.id.statusMO);
                    }
                    convertView.setTag(保持器);                }                其他{                    支架=(ViewHolder)convertView.getTag();
                }
            //布尔标志= FALSE;
            //最后弦乐体= message.getBody();
                convertView.setOnClickListener(新OnClickListener(){
                    私人INT POS =位置;                    @覆盖
                    公共无效的onClick(视图v){                        Toast.makeText(背景下,点击 - + POS,Toast.LENGTH_SHORT)
                                。显示();                        查看newConvertView = NULL;
                        如果(!message.getIsMO()){
                        newConvertView = mInflater.inflate(R.layout.mycontentmtallexapand,
                                空值);
                        holder.body =(TextView中)newConvertView
                                .findViewById(R.id.bodyMTExpand);
                        holder.date =(TextView中)newConvertView
                                .findViewById(R.id.dateMTExpand);
                        holder.from =(TextView中)newConvertView
                                .findViewById(R.id.fromMTExpand);
                        holder.status =(TextView中)newConvertView
                                .findViewById(R.id.statusMTExpand);
                        }
                        其他
                        {
                            newConvertView = mInflater.inflate(R.layout.mycontentmoallexpand,
                                    空值);
                            holder.body =(TextVi`enter code here`ew)newConvertView
                                    .findViewById(R.id.bodymoExpand);
                            holder.date =(TextView中)newConvertView
                                    .findViewById(R.id.datemoExpand);
                            holder.from =(TextView中)newConvertView
                                    .findViewById(R.id.frommoExpand);
                            holder.status =(TextView中)newConvertView
                                    .findViewById(R.id.statusmoExpand);
                        }    // newConvertView
    // .setLayoutParams(新的LayoutParams(
    // LinearLayout.LayoutParams.MATCH_PARENT,
    // LinearLayout.LayoutParams.WRAP_CONTENT));
                        holder.body.setText(message.getBody());
                        holder.date.setText(message.getDate());
                        holder.from.setText(message.getPhoneNumber());
                        holder.status.setText(将String.valueOf(message.getStatus()));
    //标志= TRUE;                    }
                });
// S = body.substring(0,20);
                holder.body.setText(message.getBody());
            holder.date.setText(message.getDate());
            holder.from.setText(message.getPhoneNumber());
            holder.status.setText(将String.valueOf(message.getStatus()));            返回convertView;        }


解决方案

在的onclick(convertView的)尝试使用convertView而不是创建新的视图(newConvertview),先删除convertView元素,然后将其扩充新的布局。

希望这wroks你..

I have a listview in which I use two diferent layouts(mycontentmtall or mycontenmotall). I want to change these two layouts on click (again when I click an object in a row to chose one from the two new layouts I created(mycontentmtallexapand or mycontentmoallexpand) ).

I face the problem where when I click an item in listview i dont see the layout change.

    @Override
            public View getView(final int position, View convertView,
                    ViewGroup parent) {

                 final ViewHolder holder;
                // int type = getItemViewType(position);
                final Message message = getItem(position);

                if (convertView == null) {

                    holder = new ViewHolder();
                    // if (type == TYPE_MT) {
                    if (!message.getIsMO()) {
                        convertView = mInflater.inflate(R.layout.mycontentmtall,
                                null);
                        holder.body = (TextView) convertView
                                .findViewById(R.id.bodyMT);
                        holder.date = (TextView) convertView
                                .findViewById(R.id.dateMT);
                        holder.from = (TextView) convertView
                                .findViewById(R.id.fromMT);
                        holder.status = (TextView) convertView
                                .findViewById(R.id.statusMT);
                    } else {
                        convertView = mInflater.inflate(R.layout.mycontentmoall,
                                null);
                        holder.body = (TextView) convertView
                                .findViewById(R.id.bodyMO);
                        holder.date = (TextView) convertView
                                .findViewById(R.id.dateMO);
                        holder.from = (TextView) convertView
                                .findViewById(R.id.fromMO);
                        holder.status = (TextView) convertView
                                .findViewById(R.id.statusMO);
                    }
                    convertView.setTag(holder);

                }

                else {

                    holder = (ViewHolder) convertView.getTag();
                }
            //  Boolean flag = false;


            //  final String body = message.getBody();
                convertView.setOnClickListener(new OnClickListener() {
                    private int pos = position;

                    @Override
                    public void onClick(View v) {

                        Toast.makeText(context, "Click-" + pos, Toast.LENGTH_SHORT)
                                .show();



                        View newConvertView = null;
                        if (!message.getIsMO()){
                        newConvertView = mInflater.inflate(R.layout.mycontentmtallexapand,
                                null);
                        holder.body = (TextView) newConvertView
                                .findViewById(R.id.bodyMTExpand);
                        holder.date = (TextView) newConvertView
                                .findViewById(R.id.dateMTExpand);
                        holder.from = (TextView) newConvertView
                                .findViewById(R.id.fromMTExpand);
                        holder.status = (TextView) newConvertView
                                .findViewById(R.id.statusMTExpand);


                        }
                        else
                        {
                            newConvertView = mInflater.inflate(R.layout.mycontentmoallexpand,
                                    null);
                            holder.body = (TextVi`enter code here`ew) newConvertView
                                    .findViewById(R.id.bodymoExpand);
                            holder.date = (TextView) newConvertView
                                    .findViewById(R.id.datemoExpand);
                            holder.from = (TextView) newConvertView
                                    .findViewById(R.id.frommoExpand);
                            holder.status = (TextView) newConvertView
                                    .findViewById(R.id.statusmoExpand);
                        }

    //                  newConvertView
    //                              .setLayoutParams(new LayoutParams(
    //                                      LinearLayout.LayoutParams.MATCH_PARENT,
    //                                      LinearLayout.LayoutParams.WRAP_CONTENT));
                        holder.body.setText(message.getBody());
                        holder.date.setText(message.getDate());
                        holder.from.setText(message.getPhoneNumber());
                        holder.status.setText(String.valueOf(message.getStatus()));
    //                  flag = true;

                    }
                });
//  s=body.substring(0, 20);
                holder.body.setText(message.getBody());
            holder.date.setText(message.getDate());
            holder.from.setText(message.getPhoneNumber());
            holder.status.setText(String.valueOf(message.getStatus()));

            return convertView;

        }

解决方案

In onclick() of convertView try to use convertView instead creating new view(newConvertview) , first remove elements in convertView and then inflate new layout on it.

Hope this wroks for you ..

这篇关于在列表视图更改行的内容时,在视图的onClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆