Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 滚动时更改ListView动态数据行_Android_Android Layout_Android Listview_Android View_Android Recyclerview - Fatal编程技术网

Android 滚动时更改ListView动态数据行

Android 滚动时更改ListView动态数据行,android,android-layout,android-listview,android-view,android-recyclerview,Android,Android Layout,Android Listview,Android View,Android Recyclerview,我想将文本视图的文本和背景颜色从未上载更改为上载。。。还想改变背景色。但是,当我点击上传按钮时,它会改变所选视图的颜色和文本,但它也会对最后一个可见项+1进行相同的更改。当我在列表中滚动时,更改效果也会在其他视图上不断变化。 下面是自定义适配器getview函数的代码 在实现ListView时始终使用ViewHolder。当您只有一个“如果”和“其他”条件时,请参阅不要使用“其他如果”。用“else”代替。尝试删除else if并插入else。也许能解决你的问题。@DroidAks如果他只需要

我想将文本视图的文本和背景颜色从未上载更改为上载。。。还想改变背景色。但是,当我点击上传按钮时,它会改变所选视图的颜色和文本,但它也会对最后一个可见项+1进行相同的更改。当我在列表中滚动时,更改效果也会在其他视图上不断变化。

下面是自定义适配器getview函数的代码


在实现ListView时始终使用ViewHolder。当您只有一个“如果”和“其他”条件时,请参阅不要使用“其他如果”。用“else”代替。尝试删除else if并插入else。也许能解决你的问题。@DroidAks如果他只需要条件txt怎么办?您应该使用ViewHolder。列表视图的问题是,如果只输入“如果”条件,则在滚动列表视图后,它会对其他视图应用颜色更改。需要有“else”部分,以便在滚动时不会覆盖其他视图的颜色。@DroidAks你说得对。。。我已经改变了条件,现在它没有把改变转移到其他因素上。。请告诉我在运行时临时更改列表项的最佳方法是什么,该列表项应将消息更改为NotUploaded=>Uploaded….=>Uploaded谢谢兄弟。。。让我试试这个教程,如果它对我有用的话,我会接受你的回答:我已经在我的自定义适配器上使用了viewHolder+notifydatasetchanged来获得所需的效果。。谢谢您:
 public View getView(int position, View convertView, ViewGroup parent) {

    View v = null;

    if(convertView == null)
    {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v=inflater.inflate(R.layout.fileview,parent,false);
        TextView tv = (TextView) v.findViewById(R.id.tv_file);
        TextView tv_date = (TextView) v.findViewById(R.id.tv_fileDate);
        TextView tvFileSize = (TextView) v.findViewById(R.id.tvFileSize);
        TextView tvFileStatus = (TextView) v.findViewById(R.id.tvUploadStatus);
        ImageView _img = (ImageView) v.findViewById(R.id.iv_file);
        ImageView btnTrash = (ImageView) v.findViewById(R.id.btnTrash);
        ImageView btnEdit = (ImageView) v.findViewById(R.id.btnEdit);
        ImageView btnUpload = (ImageView) v.findViewById(R.id.btnUpload);

        btnTrash.setOnClickListener(new myclickListener(context,files[position],position));
        btnEdit.setOnClickListener(new myclickListener(context,files[position],position));
        btnUpload.setOnClickListener(new myclickListener(context,files[position],position));



        int index = files[position].lastIndexOf(".");
        String file_extention = files[position].substring(index+1,files[position].length());
        file_extention=file_extention.toLowerCase();

        if(file_extention.equals("png"))
        {
            _img.setImageResource(images[0]);
        }
        else if(file_extention.equals("txt"))
        {
            _img.setImageResource(images[1]);
        }

        if(appPreferences.getUploadValue(files[position]).equals(statusUploaded))
        {
            tvFileStatus.setTextColor(Color.WHITE);
            tvFileStatus.setText(statusUploaded);
            tvFileStatus.setBackgroundResource(R.drawable.fileview2);
        }
        else if (appPreferences.getUploadValue(files[position]).equals(statusUploading)) {
            tvFileStatus.setTextColor(Color.BLACK);
            tvFileStatus.setText(statusUploading);
            tvFileStatus.setBackgroundResource(R.drawable.fileview3);
        }



        tv.setText(files[position]);
        tvFileSize.setText("Size:" + file_sizes[position]);
        tv_date.setText(file_dates[position]);

    }
    else
    {
        v=convertView;
    }
    return v;
}