Home > Mobile >  Incompatible types: FirstFragment cannot be converted to the Context has a big yao for help
Incompatible types: FirstFragment cannot be converted to the Context has a big yao for help

Time:09-18

Package.net. Hnjdzy. Videoapp. Fragments;


import android.os.Bundle;

The import androidx. Appcompat. Widget. The SearchView;
The import androidx. Fragments. App. Fragments;

The import android. View. LayoutInflater;
The import android. View. The view;
The import android. View. ViewGroup;
The import android. Widget. LinearLayout;
The import android. Widget. TextView;

The import net. Hnjdzy. Videoapp. R;
The import net. Hnjdzy. Videoapp. Constant. ImageList;
The import net. Hnjdzy. Videoapp. Util. Utils;
The import net. Hnjdzy. Videoapp. Widget. BannerIndicator;

/* *
* A simple {@ link fragments} ttf_subclass.
*/
Public class FirstFragment extends fragments implements BannerIndicator. BannerClickListener {
Private static final String TAG="BannerIndicatorActivity";
Private View v.
Private TextView tv_pager;
Private SearchView. SearchAutoComplete sac_key;//declare a search automatically the edit box objects

Public FirstFragment () {

//Required empty public constructor
}


@ Override
Public View onCreateView (LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//to Inflate the layout for this fragment
V=inflater. Inflate (R.l ayout. Fragment_first, container, false);
super.onCreate(savedInstanceState);
Tv_pager=v. indViewById (R.i which v_pager);
//get from layout file named banner_indicator banner indicator
BannerIndicator banner=v. indViewById (R.i db anner_indicator);
LinearLayout. LayoutParams params=(LinearLayout. LayoutParams) banner. GetLayoutParams ();
Params. Height=(int) (Utils getScreenWidth (this) * 250 f/640 f).
//set the layout of the banner indicator parameter
Banner. SetLayoutParams (params);
//set the banner indicator of advertising images queue
Banner. SetImage (ImageList. GetDefault ());
//set the banner indicator AD click listener
Banner. SetOnBannerListener (this);
return v;
}
Public void onBannerClick (int position) {
String desc=the String. Format (" you click the first % d picture ", the position + 1);
Tv_pager. SetText (desc);
}


}

CodePudding user response:

Fragments parent class is not the Context, half thinking, the constructor to Fragment corresponding to the activity of the Context, direct call,

CodePudding user response:

GetActivity () to obtain the context

CodePudding user response:

The method of parameter need what type of the context, you first make sure, maybe need is the activity

CodePudding user response:

reference BDMH reply: 3/f
what type of context, the method of parameter need you to make sure, maybe need is about the activity


Agree,
In addition, getContext () can obtain the context in the fragment,
  • Related