I want to change the text and background color of the text view from "Not Uploaded" to "Uploading..." and want to change the background color as well. But when i click on the upload button it change the color and text of the selected view but it also make same changes to the last visible item+1. When I scroll through the list the change effect keep on shifting on other views as well.
我想将文本视图的文本和背景颜色从“Not Uploaded”更改为“Uploading ...”,并且还想要更改背景颜色。但是当我点击上传按钮时,它会更改所选视图的颜色和文本,但它也会对最后一个可见项+ 1进行相同的更改。当我滚动列表时,更改效果也会继续转移到其他视图上。
Here is the code for my custom adapter getview function
这是我的自定义适配器getview函数的代码
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;
}
1 个解决方案
#1
0
Always use ViewHolder
when implementing ListView
. Refer this tutorial
实现ListView时始终使用ViewHolder。请参阅本教程
#1
0
Always use ViewHolder
when implementing ListView
. Refer this tutorial
实现ListView时始终使用ViewHolder。请参阅本教程