我在片段中添加了carouselPicker,但是在
CarouselPicker.CarouselViewAdapter imageAdapter = new CarouselPicker.CarouselViewAdapter(this,itemsImages,0);
它显示我错误
错误:(85,98)错误:不兼容的类型:FragmentAction不能 转换为上下文。
如何解决此问题
package com.android.msahakyan.expandablenavigationdrawer.fragment;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.app.AppCompatActivity;
//import android.support.v7.widget.LinearLayoutManager;
//import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;
import com.android.msahakyan.expandablenavigationdrawer.R;
import com.android.msahakyan.expandablenavigationdrawer.Registration;
import java.util.ArrayList;
import java.util.List;
import in.goodiebag.carouselpicker.CarouselPicker;
/**
* A simple {@link Fragment} subclass.
* Use the {@link FragmentAction#newInstance} factory method to
* create an instance of this fragment.
*/
public class FragmentAction extends Fragment {
CarouselPicker carouselPicker1;
private static final String KEY_MOVIE_TITLE = "key_title";
public FragmentAction() {
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment.
*
* @return A new instance of fragment FragmentAction.
*/
public static FragmentAction newInstance(String movieTitle) {
FragmentAction fragmentAction = new FragmentAction();
Bundle args = new Bundle();
args.putString(KEY_MOVIE_TITLE, movieTitle);
fragmentAction.setArguments(args);
return fragmentAction;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View v = inflater.inflate(R.layout.fragment_action,container,false);
CarouselPicker carouselPicker1 = (CarouselPicker)v.findViewById( R.id.carouselPicker1 );
List<CarouselPicker.PickerItem> itemsImages = new ArrayList<>();
itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.website_design));
itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.digital_marketing));
itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.domain_registration));
itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.graphic));
itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.mob));
itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.server));
itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.software_development));
itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.marketing));
itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.ssl));
itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.domain_registration));
itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.domain_registration));
itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.domain_registration));
CarouselPicker.CarouselViewAdapter imageAdapter = new CarouselPicker.CarouselViewAdapter(this,itemsImages,0);
carouselPicker1.setAdapter(imageAdapter);
ImageButton imageButton =(ImageButton)v.findViewById(R.id.movie_icon);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity( new Intent( getActivity(), Registration.class ) );
}
});
return v;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Drawable movieIcon = ResourcesCompat.getDrawable(getResources(), R.drawable.webdesign, getContext().getTheme());
// if (movieIcon != null) {
// movieIcon.setColorFilter(ContextCompat.getColor(getContext(), R.color.pink), PorterDuff.Mode.SRC_ATOP);
//}
((ImageButton) view.findViewById(R.id.movie_icon)).setImageDrawable(movieIcon);
String movieTitle = getArguments().getString(KEY_MOVIE_TITLE);
((TextView) view.findViewById(R.id.movie_title)).setText(movieTitle);
}
}
答案 0 :(得分:0)
将其更改为
CarouselPicker.CarouselViewAdapter imageAdapter = new CarouselPicker.CarouselViewAdapter(this.getContext(),itemsImages,0);
希望这会有所帮助