How to finish an activity from an Adapter..?

前端 未结 10 612
野趣味
野趣味 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 08:49

    close Activity form Class Custom Adapter just in method

     @Override
      public void onClick(View v) {
        MyApplication.value=mCompany.getCompanyId();
        Intent intent = new Intent(MyApplication.context, VaasetActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
       intent.putExtra("ID_COMPANY",mCompany.getCompanyId());
        MyApplication.context.startActivity(intent);
        ((Activity)context).finish();
      }
    });
    
    0 讨论(0)
  • 2020-12-13 08:51

    For Kotlin code:

    (context as Activity).finish()
    
    0 讨论(0)
  • 2020-12-13 08:55

    i have not used it but i hope it will work. use: "this.recreate()" if you are want to reload it from within the activity.

    if you want to reload it from Adapter then use: "((Activity)context).recreate()"

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

    Typecast your activity name with context and finish activity

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

    In adapter it will work

    ((Activity)view.getContext()).finish();
    
    0 讨论(0)
  • 2020-12-13 09:07

    Code for this is ((Activity)context).finish();and complete code is

    holder.cardUsers.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent1=new Intent(mcontext,AstroChatPanel.class);
            intent1.putExtra("mobile",userslist.get(position).getMobile());
            intent1.putExtra("name",userslist.get(position).getName());
            intent1.putExtra("type","admin");
            mcontext.startActivity(intent1);
            ((Activity)mcontext).finish();
        }
    });
    
    0 讨论(0)
提交回复
热议问题