同时滚动列表视图

同时滚动列表视图

本文介绍了所选项目的问题,同时滚动列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的code,显示的标签列表现在,当我选择一个刻度线所选择的项目之前显示的项目。

和我移动到下一个活动。现在的问题是,当我来到这个活动再次使用后退按钮和滚动的ListView的刻度标记显示多个标签,而不是单一的一个我选中了。

任何一个指导我什么错误,我在这里干什么?

  ImageView的selectedTickImageView;
getview {

    如果(convertView == NULL){
                        convertView = mInflater.inflate(R.layout.row_tags_archives,NULL);
                        持有人=新ViewHolder();
                        holder.tickImageView =(ImageView的)convertView.findViewById(R.id.tick_image_view);
                        holder.titletextView =(TextView中)convertView.findViewById(R.id.tv_tags_archives);
                        holder.tickImageView.setTag(位置);

                        convertView.setOnClickListener(新View.OnClickListener(){

                            @覆盖
                            公共无效的onClick(查看paramView){
                                    如果(selectedTickImageView!= NULL){
                                        selectedTickImageView.setVisibility(View.GONE);
                                    }

                                    ImageView的tickImageView =(ImageView的)paramView.findViewWithTag(位置);
                                    tickImageView.setVisibility(View.VISIBLE);

                                    selectedTickImageView = tickImageView;
                                    S =标签[定位];
                                    S = S.replace(, - );
                                    S = S.toLowerCase();
                                    意向意图=新的意图(H pressTagsorUpdatesActivity.this,H pressSummariesActivity.class);
                                    startActivity(意向);
                            }});

                        convertView.setTag(保持器);

                      } 其他 {
                        支架=(ViewHolder)convertView.getTag();
                      }
 

解决方案

一类标签+选择的领域将是解决这一问题的更有效的方式,但我已经使用布尔的全球选定阵列跟踪选定的项目。

 如果(convertView == NULL){
                    //私人语境_context =;
                    LayoutInflater mInflater = LayoutInflater.from(H pressTagsorUpdatesActivity.this);
                    convertView = mInflater.inflate(R.layout.row_tags_archives,NULL);
                    持有人=新ViewHolder();
                    holder.tickImageView =(ImageView的)convertView.findViewById(R.id.tick_image_view);
                    holder.tickImageView.setTag(位置);
                    holder.titletextView =(TextView中)convertView.findViewById(R.id.tv_tags_archives);




                    convertView.setTag(保持器);

                  } 其他 {
                    支架=(ViewHolder)convertView.getTag();
                  }


                如果(选择[​​位置] ==真)
                {
                    holder.tickImageView.setVisibility(View.VISIBLE);
                }其他
                {
                    holder.tickImageView.setVisibility(View.GONE);

                }


                convertView.setOnClickListener(新View.OnClickListener(){

                    @覆盖
                    公共无效的onClick(查看paramView){

                        ImageView的tickImageView =(ImageView的)paramView.findViewWithTag(位置);
                        tickImageView.setVisibility(View.VISIBLE);
                            选择[位置] =真;

                            S =标签[定位];
                            S = S.replace(, - );
                            S = S.toLowerCase();
                            意向意图=新的意图(H pressTagsorUpdatesActivity.this,H pressSummariesActivity.class);
                            startActivity(意向);
                    }});
 

i am using following code to display list of tags now when i select any item a tick mark is displayed before that selected item.

and i move to next activity. now problem is when i come to this activity again using back button and scroll on that listview tick marks are displayed before many tags instead of single one i selected.

any one guide me what mistake am i doing here?

ImageView selectedTickImageView;
getview{

    if (convertView == null) {
                        convertView = mInflater.inflate(R.layout.row_tags_archives, null);
                        holder = new ViewHolder();
                        holder.tickImageView= (ImageView)convertView.findViewById(R.id.tick_image_view);
                        holder.titletextView = ( TextView )convertView.findViewById(R.id.tv_tags_archives);
                        holder.tickImageView.setTag(position);

                        convertView.setOnClickListener(new View.OnClickListener() {

                            @Override
                            public void onClick(View paramView) {
                                    if(selectedTickImageView != null){
                                        selectedTickImageView.setVisibility(View.GONE);
                                    }

                                    ImageView tickImageView = (ImageView)paramView.findViewWithTag(position);
                                    tickImageView.setVisibility(View.VISIBLE);

                                    selectedTickImageView =tickImageView;
                                    S=tags[position];
                                    S=S.replace(" ", "-");
                                    S=S.toLowerCase();
                                    Intent intent = new Intent(HPressTagsorUpdatesActivity.this ,HPressSummariesActivity.class);
                                    startActivity(intent);
                            }});

                        convertView.setTag(holder);

                      } else {
                        holder = (ViewHolder) convertView.getTag();
                      }
解决方案

a class with tag + selected fields would be more efficient way to solve this problem but i have used a global selected array of boolean to keep track of selected item.

if (convertView == null) {
                    //private Context _context = ;
                    LayoutInflater mInflater = LayoutInflater.from(HPressTagsorUpdatesActivity.this);
                    convertView = mInflater.inflate(R.layout.row_tags_archives, null);
                    holder = new ViewHolder();
                    holder.tickImageView= (ImageView)convertView.findViewById(R.id.tick_image_view);
                    holder.tickImageView.setTag(position);
                    holder.titletextView = ( TextView )convertView.findViewById(R.id.tv_tags_archives);




                    convertView.setTag(holder);

                  } else {
                    holder = (ViewHolder) convertView.getTag();
                  }


                if(selected[position] == true)
                {
                    holder.tickImageView.setVisibility(View.VISIBLE);
                }else
                {
                    holder.tickImageView.setVisibility(View.GONE);

                }


                convertView.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View paramView) {

                        ImageView tickImageView = (ImageView)paramView.findViewWithTag(position);
                        tickImageView.setVisibility(View.VISIBLE);
                            selected[position] = true;

                            S=tags[position];
                            S=S.replace(" ", "-");
                            S=S.toLowerCase();
                            Intent intent = new Intent(HPressTagsorUpdatesActivity.this ,HPressSummariesActivity.class);
                            startActivity(intent);
                    }});

这篇关于所选项目的问题,同时滚动列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 12:32