如何刷新选项卡活动中的列表视图?

发布于 2024-12-26 07:56:52 字数 2236 浏览 1 评论 0原文

您好,我有一个选项卡活动,显示项目列表(ListView)。此listview 每行都有一个按钮。我正在我的自定义适配器类中处理此按钮 clickListener,该类扩展了 BaseAdapter 类。现在我想要的是,当我单击此按钮时,该项目应该从 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;

}

Hi i have a tab activity which show a list of items(ListView). This listview has a button in each row. I am handling this button clickListener in my custom adapter class which extends the BaseAdapter class. Now what i want is when i click on this button the item should be remove from the listview and listview should get a refresh. How to do this?

ok I think my code can explain it

 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;

}

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

噩梦成真你也成魔 2025-01-02 07:56:52

根据单击的行的位置,从支持 Adapter 示例的 Collection 中删除一个项目:

myArrayList.remove(position);

然后使用以下方法通知列表数据已更改:

adapter.notifyDataSetChanged();

Based on the position of the row that was click remove an item from the Collection that is backing the Adapter example :

myArrayList.remove(position);

then notify the list that the data is changed using :

adapter.notifyDataSetChanged();
烛影斜 2025-01-02 07:56:52

你可以做到的。首先在按钮的操作侦听器中,更新列表视图的适配器(我的意思是添加/删除适配器中不需要的元素),并且需要调用 urlistview.notifydatasetchange(true)。这将刷新您的列表视图

You can do it. First in your action listener of your button, update your adapter of list view(i mean add/remove the elements that you dont want from your adapter) and you need to call urlistview.notifydatasetchange(true). this will refresh your list view

被翻牌 2025-01-02 07:56:52

您的代码可能有助于获得准确的答案,但从高层来看,这就是您可能需要做的,您需要从实例化自定义适配器类时传递的值列表中删除选定的条目。第一次尝试时,您选择的条目将为空,因此您无需删除任何内容。

Your code may help in getting exact answer, but high level this is what you may need to do, you need to delete the selected entry from the list of values you are passing while instantiating your custom adapter class. On First attempt, your selected entry will be empty, so you don't need to delete anything.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文