简体   繁体   English

单击自定义列表视图中的按钮时需要重新加载mainActivity控制器

[英]need to reload mainActivity controller on click of button located in customized listview

To make my question more understandable let me start with an image of my view. 为了使我的问题更容易理解,让我从我的观点开始。

在此处输入图片说明

I have an xml file named Menu, that has customized list view in it. 我有一个名为Menu的xml文件,其中具有自定义列表视图。 I have created another xmlview named MenuCell as below. 我创建了另一个名为MenuCell的xmlview,如下所示。
在此处输入图片说明

Now tapping on add button I'm adding Item to the cart. 现在点击添加按钮,我将商品添加到购物车。 which is working perfectly fine except not updating value of a cart (top right corner) on click event. 除了在点击事件中不更新购物车(右上角)的值之外,该工具运行得非常好。 But If I navigate to different view and come back to this view at this point I'm getting number of items added in the cart reflected properly. 但是,如果我导航到其他视图并返回到此视图,则可以正确反映购物车中添加的项目数。 So How Can I reload my controllerview when I tap in my arradepter view's ImageButton. 因此,当我点击arradepter视图的ImageButton时,如何重新加载controllerview。

this is my adapter code 这是我的适配器代码

holder.imageButton1.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                addItem(position);
                notifyDataSetChanged();
            }
        });

void addItem(int position) {

        count++;
        }

Where count is item added count. 计数是项目添加计数。

If anyone can tell How am I able to reflect this count of my arrayadpter class to my other controller class that holds actual list view. 如果有人能告诉我如何将我的arrayadpter类的计数反映到其他拥有实际列表视图的控制器类中。

Any Help will be appreciated 任何帮助将不胜感激

Thanks in advance. 提前致谢。

Send the reference of your controller to your list adapter class. 将控制器的引用发送到列表适配器类。 In the controller I guess you have a method that computes some data and after that call update the view that holds cart data summary. 我猜在控制器中,您有一个计算一些数据的方法,并且在调用之后更新了保存购物车数据摘要的视图。 Just make sure that update is on UI thread. 只要确保更新在UI线程上即可。

You need to use callback feature to get notified to your activity , hence add button is part of list component so you can update your list view. 您需要使用回调功能来通知您的活动,因此添加按钮是列表组件的一部分,因此您可以更新列表视图。

Here are few links for understanding of call back using interface 以下是一些用于了解使用界面回叫的链接

http://cleancodedevelopment-qualityseal.blogspot.in/2012/10/understanding-callbacks-with-java.html


http://stackoverflow.com/questions/11577695/what-is-a-call-back-interface-in-java

After : 之后:
notifyDataSetChanged();
just add: 只需添加:
YourList.invalidateViews();
YourList.scrollBy(0, 0);

Your List is not refreshing at the instant because you have to refresh data of your adapter and then call notifyDataSetChanged(); 您的列表不会立即刷新,因为您必须刷新适配器的数据,然后调用notifyDataSetChanged();。

Suppose You have the data in an array which is visible in textview.Then In your function addItem add the data into ur array and then call notifyDataSetChanged(); 假设您将数据存储在textview中可见的数组中。然后在函数addItem中将数据添加到ur数组中,然后调用notifyDataSetChanged();。 This will immediately tell the list view that watever data it is containing is changed so time to refresh. 这将立即告诉列表视图,其中包含的Watever数据已更改,因此刷新时间到了。

If you can paste more of ur adapter code i can be helpful 如果您可以粘贴更多的ur适配器代码,我会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过单击 android 中的按钮重新加载 listView? - How to reload the listView on click of a button in android? 当我单击位于顶视图活动中的按钮并且 MainActivity 未处于活动状态时,剪贴板返回 null - Clipboard returns null when I click on the button located in the top view activity and when MainActivity is not active 如何通过Robotium自动化单击位于ListView中位置2的按钮? - How to click on a button, which is located at position 2 in ListView via robotium automation? 在listview项目按钮单击时需要AsyncTask的帮助 - Need help with AsyncTask on listview item button click 什么时候保存一个活动实例并在listview按钮上重新加载它,然后单击? - When to save an instance of an activity and reload it on a listview button click? 自定义listView中的按钮无法正常工作? - Button in a customized listView is not working properly? 自定义ListView上的按钮对话框 - Dialog from button on a customized ListView 自定义ListView-当我单击列表内的按钮时获取项目的ID - custom ListView - get id of item when i click on a button located inside the list 单击按钮,然后单击ListView - Button click and ListView click 在按钮上单击重新加载适配器 - on button click reload adapter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM