问题描述
- 如何在tab activity中刷新listview?
-
在一个tab activity中显示一列items。这个listview 在每一行中都有一个按钮。我在
自定义的adapter 类中处理按钮的clickListener事件,这个类继承BaseAdapter类。但是现在我想实现当我点击这个按钮时,item应该从listview 中删除, listview应该刷新一次。
如何实现?public View getView(final int position, View convertView, ViewGroup parent) { ViewHolder holder; final ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE); if(convertView==null) { convertView = mInflater.inflate(R.layout.list_item, null); holder = new ViewHolder(); // holder.appSize = (TextView)convertView.findViewById(R.id.app_size); holder.appName = (TextView)convertView.findViewById(R.id.app_name); holder.app_icon = (ImageView)convertView.findViewById(R.id.app_icon); holder.button = (Button)convertView.findViewById(R.id.uninstall); if(kill_OR_uninstall) { holder.button.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_DELETE); intent.setData(Uri.parse("package:"+package_names.get(position))); context.startActivity(intent); } }); } else { holder.button.setText("End"); holder.button.setOnClickListener(new OnClickListener() { public void onClick(View v) { am.restartPackage(package_names.get(position)); } }); } convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.appName.setText((String)app_details.get(position).get(APP_NAME)); holder.app_icon.setImageDrawable((Drawable)app_details.get(position).get(APP_ICON)); // holder.appSize.setText(app_details.get(position).get(APP_SIZE)+ " KB"); return convertView; }
解决方案
去除掉你点击的item后直接notifydatachanged();
时间: 2024-11-02 09:45:29