在开源的SwipeListView中滑动Item到一半时调用适配器的数据刷新时比较卡顿

发布于 2022-09-01 16:34:56 字数 2811 浏览 30 评论 0

我在todoAdapter适配器中想动态的设置一个swipelistview滑动后的back view它布局的颜色跟一个ImageView的图片。todoAdapter的getView代码如下:

	@Override
	public View getView(int itemPosition, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		String taskName = listItems.get(itemPosition).getTaskName();
		String projectName = listItems.get(itemPosition).getProjectName();
		boolean isChecked = listItems.get(itemPosition).getTaskState();
		if (convertView == null) {
			LayoutInflater mInflater = (LayoutInflater) mContext
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = mInflater.inflate(R.layout.today_todo_item, null);
			holder = new ViewHolder();
			holder.taskName = (TextView) convertView
					.findViewById(R.id.show_task_info);
			holder.projectName = (TextView) convertView
					.findViewById(R.id.show_project_info);
			holder.taskCheckBox = (CheckBox)convertView.findViewById(R.id.today_task_checkbox);
			holder.backgroundColor = (RelativeLayout)convertView.findViewById(R.id.id_back);
			holder.bkLogo = (ImageView)convertView.findViewById(R.id.swipe_bk_image);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		((SwipeListView) parent).recycle(convertView, itemPosition);
		// Toast.makeText(mContext, taskName, Toast.LENGTH_SHORT).show();
		holder.taskName.setText(taskName);
		holder.projectName.setText(projectName);
		holder.taskCheckBox.setChecked(isChecked);
		holder.backgroundColor.setBackgroundColor(mContext.getResources().getColor(Constant.resBackgroundColorId));
		holder.bkLogo.setImageDrawable(mContext.getResources().getDrawable(Constant.resBackgroundImageId));
		
		return convertView;
	}

它主要的作用效果图如下:
clipboard.png

clipboard.png
我想滑到一半时更换那个图片跟背景的颜色,但是滑到一半时突然的卡顿了一下。
这是当item移动时的片段代码,我在调用 todoAdapter.notifyDataSetChanged()时毕竟卡顿。

			@Override
			public void onMove(int position, float x) {
				/*
				 * if(x >= screenInfo.getWidth()/2){ Toast.makeText(mContext,
				 * "到达屏幕宽度的一半", Toast.LENGTH_LONG).show(); }
				 */
				// Toast.makeText(mContext,
				// String.valueOf(Constant.tUpDistance), 1).show();
				if (Math.abs(x) >= swipeListView.getWidth() / 2) {
					Constant.resBackgroundColorId = R.color.use_blue;
					Constant.resBackgroundImageId = R.drawable.tomato_clock;
					todoAdapter.notifyDataSetChanged();
//					runBackView.execute("");
				}
			}

我想问有什么合适的解决办法,不让listview的item滑动的时候卡顿。我试过AsyncTask异步线程,和handler,但是不会用。希望有具体可行的代码。。。谢谢!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文