How to finish an activity from an Adapter..?

前端 未结 10 613
野趣味
野趣味 2020-12-13 08:39

I tried with passing context of activity into the adapter and then i tried context.finish(); But its giving me one error like The method fini

相关标签:
10条回答
  • 2020-12-13 09:09

    Try with the following code:

    public YourAdapterName(......,Context context){
    
    ...
    
    this.myContext=context;
    }
    

    And in your adapter getView()

    btn.setOnClickListener(new Button.OnClickListener() {
    
        @Override
        public void onClick(View v) {
            ((YourActivityName)myContext).yourDesiredMethod();
    
        }
    });
    
    0 讨论(0)
  • 2020-12-13 09:13

    type cast it with activity.

    ((Activity)context).finish();
    
    0 讨论(0)
  • 2020-12-13 09:14

    Try passing your Activity as an activity parameter, then you'll be able to call finish() on it. Hope this helps.

    0 讨论(0)
  • 2020-12-13 09:15

    In your custom adapter try to call finish use below code

    ((Activity)context).finish();
    
    0 讨论(0)
提交回复
热议问题