Home > Mobile >  How to use the INTENT in the adapter to call the new ACTIVITY
How to use the INTENT in the adapter to call the new ACTIVITY

Time:09-20

I put a listview in fragments and listen for each item in the Adapter, and then want to listen with the intent to start the new a new activity, but the intent intent=new intent (context, CotDe. Class); It always feels wrong, that how to get the context?

CodePudding user response:

Context can be at your new Adapter as a constructor parameter passing in, but if you want to startActivity requires as activity, and went in

CodePudding user response:

Fragments have a method, getActivity (). You can get the context, and then for setonitemclick, that is to say, your method of the context can be directly replaced with getActivity ().

CodePudding user response:

New Adapter (Context Context)

CodePudding user response:

Inside the adapter with the context. StartActivity (intent);

CodePudding user response:

Remember, as a convenient, later development inside the adapter into the context, even if you're not using,

CodePudding user response:

Don't direct this can

CodePudding user response:


Public void onClick (View v) {
Click on the entry//prompt box
Toast. MakeText (v.g etContext (),
"You click on the letter is:" + holder. The textView. The getText (), Toast. LENGTH_LONG.) the show ();
//click items to jump to another Activity
Intent Intent=new Intent (v.g etContext (), AnotherActivity. Class);
V.g etContext (.) startActivity (intent);
}
});

CodePudding user response:


Declarations of variables statement after the global variables in the Adapter a Context Context Context,
Adapter in the constructor and a context context,
Public void myadapter (Context Context, List The list) {
Text=context this.com
};

Jump:
Intent I=new Intent (context, Acy. Class);
The context. StartActivity (intent);

CodePudding user response:

Public class ViewHolder extends RecyclerView. ViewHolder {
Createing_meeting_item_View item_view;

Public ViewHolder (@ NonNull View View) {
Super (view);
Item_view=view. The findViewById (R.i d.i tem_view);
Item_view. SetOnClickListener (new View. An OnClickListener () {
@ Override
Public void onClick (View v) {

Intent Intent=new Intent (mContext, Meeting_Activity. Class);
MContext. StartActivity (intent);
}
});
}
}
  • Related