Opening new fragment from RecyclerView button within a fragment - android

I have a fragment running that has part of its layout view load a RecyclerView Card. From within this card I want to launch a new fragment that opens a full screen layout.
public class MemoriesFragment extends Fragment {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MemListFragment fragment = new MemListFragment();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.placeholder, fragment);
fragmentTransaction.commit();
}
#Override
public View onCreateView(#NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_authoring_memory_menu_1, container, false);
return view;
}}
That's the main fragment. The next one is the fragment that creates and populates the RecyclerView
public class MemListFragment extends Fragment {
ImageButton button1;
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_authoring_memory_list, container,false);
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.listRecyclerView);
ListAdapter listAdapter = new ListAdapter();
recyclerView.setAdapter(listAdapter);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(layoutManager);
button1 = view.findViewById(R.id.memory_image);
return view;
}}
This is the RecyclerView
public class Adapter extends RecyclerView.Adapter<Adapter.ViewHolder> {
private LayoutInflater layoutInflater;
private List<String> data;
public ImageButton memory_image;
public Adapter(MemoriesFragment Context, List<String> data){
// this.layoutInflater = LayoutInflater.from();
this.data = data;
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int i) {
View view = layoutInflater.inflate(R.layout.memory_view,viewGroup,false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull ViewHolder viewHolder, int i) {
// bind the textview with data received
String title = data.get(i);
viewHolder.textTitle.setText(title);
// similarly you can set new image for each card and descriptions
viewHolder.memoryButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
AppCompatActivity activity = (AppCompatActivity) view.getContext();
Fragment MemoryDetails = new MemoryDetails();
activity.getSupportFragmentManager().beginTransaction().replace(R.id.placeholder, MemoryDetails).addToBackStack(null).commit();
}
});
}
#Override
public int getItemCount() {
return data.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
// Define UI components here
TextView textTitle;
ImageButton memoryButton;
public ViewHolder(#NonNull View itemView) {
super(itemView);
textTitle = itemView.findViewById(R.id.textTitle);
memoryButton = itemView.findViewById(R.id.memory_image);
}
}
}
The recylerview is created with memory_view.xml which just has text and an imagebutton named memory_image. When I run this code it crashes when I click the Image Button.
Edit: added error log below
2020-02-21 16:50:29.334 19558-19558/com.app.emotivo E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.app.emotivo, PID: 19558
java.lang.IllegalStateException: Could not find method onClick(View) in a parent or ancestor Context for android:onClick attribute defined on view class androidx.appcompat.widget.AppCompatImageButton with id 'memory_image'
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.resolveMethod(AppCompatViewInflater.java:434)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:391)
at android.view.View.performClick(View.java:6256)
at android.view.View$PerformClick.run(View.java:24701)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

i am not sure if it works but can you try using supportfragmentmanager in the memories fragment too , and cast your the the result of itemView.findViewById(R.id.memory_image)to an ImageButton like that (ImageButton)itemView.findViewById(R.id.memory_image)

the display of the fragment inside the adapter is not a good thing.
I think first of all use the navigation on Android Jetpack
Or use RxJava and transfer the formatting representation from adapter to fragment.

Related

How to replace a fragment with another fragment with a web view to open different URLs by clicking on different items in the recyclerview?

My problem is, I have a recyclerview implemented in a fragment called "FragmentNewsItems" that lists out the set of news (images + text) in cardview. So my task is, to make the app, so that when I click on one of those items in the recyclerview, the app would replace it with another fragment with a web view.
Some good people advised me to create a click event:
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {
// add this line
private AdapterView.OnItemClickListener onItemClickListener;
public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private ImageView image;
private TextView text;
FragmentNewsItems fragmentNewsItems = new FragmentNewsItems();
public ViewHolder(#NonNull View itemView) {
super(itemView);
image = itemView.findViewById(R.id.image);
text = itemView.findViewById(R.id.text);
itemView.setOnClickListener(this);
}
#Override
public void onClick(View view) {
mAdapter.onItemHolderClick(ViewHolder.this);
}
}
public void setOnItemClickListener(AdapterView.OnItemClickListener onItemClickListener) {
this.onItemClickListener = onItemClickListener;
}
private void onItemHolderClick(ViewHolder holder) {
if (onItemClickListener != null)
onItemClickListener.onItemClick(null, holder.itemView, holder.getAdapterPosition(), holder.getItemId());
}
}
and then add the click event to the fragment:
public class FragmentNewsItems extends Fragment implements AdapterView.OnItemClickListener{
View view;
private RecyclerView recyclerView;
private List<NewsItems> cyberNews;
private FragmentNewsItems fragmentNewsItems;
public FragmentNewsItems(){
}
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.f_news_items_layout, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.news_items_recycler_view);
RecyclerViewAdapter recyclerAdapter = new RecyclerViewAdapter(getContext(), cyberNews);
// add this line
recyclerAdapter .setOnItemClickListener(this);
recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
recyclerView.setAdapter(recyclerAdapter);
return view;
}
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
cyberNews = new ArrayList<>();
cyberNews.add(new NewsItems(R.drawable.cyber1, "The of cybersecurity in 5G-connected world"));
cyberNews.add(new NewsItems(R.drawable.cyber2, "Google discovered several iPhone security flaws, and Apple still hasn't patched one"));
cyberNews.add(new NewsItems(R.drawable.cyber3, "WhatsApp and Telegram media files aren't so secure"));
cyberNews.add(new NewsItems(R.drawable.cyber4, "Microsoft Exposes Russian Cyberattacks on Phones, Printers, Video Decoders"));
cyberNews.add(new NewsItems(R.drawable.cyber5, "Tesla demonstrated the power of The Internet of Things"));
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// here open new activity or replace fragment which have webview.
}
Like this:
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// here open new activity or replace fragment which have webview.
}
But you see a comment which says open a new activity or replace fragment which have a webview. I tried multiple times to replace with another fragment, but it simply does not open my fragment. I mean, it loads the layout, but does not replace with another fragment. I am a new to Android, and to be honest I have no idea what's wrong. Can you help me with coding?
create a new fragment for web view and pass your data and replace new fragment using your activity:
check my answer for this question:
https://stackoverflow.com/questions/58680300

Android - RecyclerView multiplies itself every time device is rotated

I have a landscape configuration for one of my app's activities. This activity contains a fragment and this fragment contains one textview and one recyclerview. Everytime when i switch in between portrait and landscape modes, the recyclerview leaves the view of itself like however it was before i turned the device. It might be a little difficult to understand what i try to ask here, so i recorded a gif for that.
https://giphy.com/gifs/3Wv7NAtT8ezP1SQhDu
This is my activity
public class RecipeStepsActivity extends AppCompatActivity {
static Recipe recipe;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recipe_steps);
if (StepDetailActivity.SDA_TAG.equals(StepDetailActivity.NEGATIVE))
recipe = getIntent().getParcelableExtra("recipe");
Bundle b = new Bundle();
b.putParcelable("recipe", recipe);
ActionBar ab = getSupportActionBar();
if (ab != null)
ab.setTitle(recipe.getName());
RecipeStepsFragment recipeStepsFragment = new RecipeStepsFragment();
recipeStepsFragment.setArguments(b);
FragmentManager fm = getSupportFragmentManager();
fm.beginTransaction().add(R.id.frame_layout_steps, recipeStepsFragment).commit();
}
}
This is my fragment
public class RecipeStepsFragment extends Fragment {
#BindView(R.id.recipe_steps_rv)
RecyclerView recyclerView;
#BindView(R.id.ingredients_tv)
TextView tv_ingredients;
List<Step> steps;
public RecipeStepsFragment(){}
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_recipe_steps, container, false);
}
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ButterKnife.bind(this, view);
List<Ingredients> ingredients;
Recipe recipe = getArguments().getParcelable("recipe");
steps = recipe.getSteps();
initRecyclerView();
ingredients = recipe.getIngredients();
String ingredientsAppended = "INGREDIENTS" + "\n\n";
if (ingredients == null){
ingredientsAppended = "Not Available";
} else {
for (int a = 0 ; a < ingredients.size() ; a++) {
Ingredients i = ingredients.get(a);
ingredientsAppended += String.valueOf(i.getQuantity()) + " " +
i.getMeasure() + " " +
i.getIngredient();
if (a+1 != ingredients.size()){
ingredientsAppended += '\n';
}
}
}
tv_ingredients.setText(ingredientsAppended);
if(savedInstanceState != null){
recyclerView.scrollToPosition(savedInstanceState.getInt("position"));
}
}
#Override
public void onSaveInstanceState(#NonNull Bundle outState) {
outState.putInt("position", recyclerView.getVerticalScrollbarPosition());
super.onSaveInstanceState(outState);
}
private void initRecyclerView(){
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL));
RecipeStepsRecyclerAdapter recipeStepsRecyclerAdapter =
new RecipeStepsRecyclerAdapter(steps, new RecipeStepsRecyclerAdapter.ClickListener() {
#Override
public void onItemClick(int clickedItemPosition) {
Intent intentToStepDetail = new Intent(getActivity(), StepDetailActivity.class);
Step step = steps.get(clickedItemPosition);
intentToStepDetail.putExtra("step", step);
startActivity(intentToStepDetail);
}
}, getContext());
recyclerView.setAdapter(recipeStepsRecyclerAdapter);
recipeStepsRecyclerAdapter.notifyDataSetChanged();
}
}
This is my adapter
public class RecipeStepsRecyclerAdapter extends RecyclerView.Adapter<RecipeStepsRecyclerAdapter.ViewHolder> {
private List<Step> stepList;
private LayoutInflater mInflater;
final private ClickListener clickListener;
public RecipeStepsRecyclerAdapter(List<Step> stepList, ClickListener clickListener, Context context){
this.stepList = stepList;
this.clickListener = clickListener;
mInflater = LayoutInflater.from(context);
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = mInflater.inflate(R.layout.recipe_steps_recyclerview_adapter, parent, false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
Step step = stepList.get(position);
String stepContent = step.getShortDescription();
holder.listingNumber.setText(String.valueOf(position+1));
holder.stepContent.setText(stepContent);
}
#Override
public int getItemCount() {
return stepList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
TextView listingNumber;
TextView stepContent;
private ViewHolder(View itemView) {
super(itemView);
listingNumber = itemView.findViewById(R.id.list_number_tv);
stepContent = itemView.findViewById(R.id.step_content_tv);
itemView.setOnClickListener(this);
}
#Override
public void onClick(View view) {
int clickedPosition = getAdapterPosition();
clickListener.onItemClick(clickedPosition);
}
}
public interface ClickListener{
void onItemClick(int clickedItemPosition);
}
}
Layout files are as I already explained above. I guess nothing special to post here.
Thanks in advance.
The problem is that you add a new fragment to the Activity every time it is created. Here's the end of your onCreate(...):
RecipeStepsFragment recipeStepsFragment = new RecipeStepsFragment();
recipeStepsFragment.setArguments(b);
FragmentManager fm = getSupportFragmentManager();
fm.beginTransaction().add(R.id.frame_layout_steps, recipeStepsFragment).commit();
The FragmentManager keeps a reference to the fragment you add to it even if the host Activity is destroyed. Thus, you keep adding new instances of the RecipeStepsFragment eventually overlaying each other and producing the seen behavior.
Don't worry, the fix is pretty simple: use replace(...) instead of add(...):
fm.beginTransaction().replace(R.id.frame_layout_steps, recipeStepsFragment).commit();
P.S.: Note, however, that replacing the current fragment with a new one every time the host activity is destroyed is not a good idea. You should check either if the savedInstanceState is null (which indicates that it's a non-recreated Activity) or if the given fragment is already added (define a tag when adding the fragment and try finding it in onCreate(...) before replacing the old one).
Every time you change the rotation of the screen your activity is destroyed and recreated. That is the reason why your list is populating with new items each time when you switch between your orientation.
So it's important you only instantiate your objects once, and not keep recreating them each time your app is recreated. Which then adds them to your list.
You can use onSaveInstanceState and onRestoreInstanceState.
If you want your app to allow orientation change, apply logic so your list don't get new items each time when activity is created.
Put configChanges attribute in your activity in menifest file
<activity android:name=".VideoActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>

Can't Access to ExpandablelistView in fragment

MainActivity on startup add a fragment layout to Relativeview, then i send a data to fragment to add it to ExpandablelistView but my app shows me error that couldn't recognize ExpandablelistView.
MainActivity:
public class MainActivity extends AppCompatActivity implements FragmentAddCatergory.onClickButtonListener {
private FragmentManager manager;
private FragmentTransaction transactionShowList;
private FragmentTransaction transactionAddCatergory;
private FragmentAddCatergory addCatergory;
private FragmentShowCategory showCategory;
private boolean addcategory;
private TextView txtAddCategory;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
manager = getFragmentManager();
transactionShowList = manager.beginTransaction();
showCategory = new FragmentShowCategory();
addCatergory=new FragmentAddCatergory();
transactionShowList.add(R.id.Fragment_container, showCategory);
transactionShowList.commit();
addcategory=false;
txtAddCategory = (TextView) findViewById(R.id.txtaddcategory);
txtAddCategory.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
ChangeFragment();
}
});
}
public void ChangeFragment(){
transactionAddCatergory=manager.beginTransaction();
if (addcategory){
transactionAddCatergory.replace(R.id.Fragment_container,addCatergory);
txtAddCategory.setText("Do you want to see your List?Show me!");
addcategory=false;
}else{
transactionAddCatergory.replace(R.id.Fragment_container,showCategory);
txtAddCategory.setText("Do you want to add a Category?Create One");
addcategory=true;
}
transactionAddCatergory.commit();
}
#Override
public void ClickButton(String group, String child) {
FragmentShowCategory a=new FragmentShowCategory();
a.showExpand(this,group,child);
}}
in last above code i make object from first fragment and send a data and in below code is code of first fragment
public class FragmentShowCategory extends Fragment {
private View view;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
view = inflater.inflate(R.layout.activity_expandable_list_view, container, false);
return view;
}
public void showExpand(Context context, String g, String c) {
Toast.makeText(context, g + " is " + c, Toast.LENGTH_LONG).show();
HashMap<String, List<String>> carsDetails = DataProvider.getInfo(g, c);
List<String> carsBrands = new ArrayList<String>(carsDetails.keySet());
ItemClass adapter = new ItemClass(context, carsDetails, carsBrands);
ExpandableListView list = (ExpandableListView) view.findViewById(R.id.expandList);
list.setAdapter(adapter);
}}
but when i ran my app, i get error that i don't know why in line of:
ExpandableListView list = (ExpandableListView) view.findViewById(R.id.expandList);
i'd appreciate to help me.
Your fragment's view hierarchy is not inflated automatically just because you created an instance of your fragment, as you do in ClickButton. The onCreateView() method that has to be called first in order to inflate your views is part of the fragment's lifecycle. You should let Android instantiate your fragment, and acquire it's instance through the FragmentManager.
This tutorial explains basics about fragments very well.

ViewPager stucks while swiping views

I have created a viewpager with tabslayout.Each view of viewpager consists of recyclerview inside fragment.The issue i am having is that when i swipe through the views it stucks while swiping in such a manner that there is no change in view and i have to swipe multiple times in order to change view.It looks that swipe event is not detected by viewpager.However if i comment out below two lines which includes setting adapter then i don't experience such issue and swipe is smooth and fast.
PlanListAdapter mAdapter = new PlanListAdapter(browsePlanModelList, getActivity());
rvBrowsePlanList.setAdapter(mAdapter);
Where am i going wrong and how can i resolve this?
Below is code of fragment and adapter-
public class FullTimeFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_browse_plan_list, container, false);
ArrayList<BrowsePlanModel> browsePlanModelList = (ArrayList<BrowsePlanModel>) getArguments().getSerializable(AppConstant.BROWSEPLANlIST);
RecyclerView rvBrowsePlanList = (RecyclerView) view.findViewById(R.id.rvBrowsePlanList);
//rvBrowsePlanList.addItemDecoration(new SimpleDividerIncludingLastItemDecoration(getResources()));
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
rvBrowsePlanList.setLayoutManager(mLayoutManager);
rvBrowsePlanList.setItemAnimator(new DefaultItemAnimator());
if(browsePlanModelList!=null)
{
BrowsePlanListAdapter mAdapter = new BrowsePlanListAdapter(browsePlanModelList, getActivity());
rvBrowsePlanList.setAdapter(mAdapter);
}
return view;
}
}
Adapter
public class PlanListAdapter extends RecyclerView.Adapter<PlanListAdapter.MyViewHolder> {
private List<BrowsePlanModel> planList;
Context mContext;
public PlanListAdapter(List<BrowsePlanModel> planList, Context mContext) {
this.mContext = mContext;
this.planList = planList;
}
#Override
public PlanListAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.sffs_item, parent, false);
return new MyViewHolder(itemView);
}
#Override
public void onBindViewHolder(PlanListAdapter.MyViewHolder holder, int position) {
holder.xyz.setText(planList.get(position).getxyx());
holder.abc.setText(planList.get(position).getabc());
}
#Override
public int getItemCount() {
return planList.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView xyz, abc;
public MyViewHolder(View itemView) {
super(itemView);
xyz = (TextView) itemView.findViewById(R.id.xyz);
abc = (TextView) itemView.findViewById(R.id.abc);
}
}
}
Use
myViewPager.setOffscreenPageLimit(number of pages in your viewpager minus 1);
If you do not do this, the pages which are not currently visible will be destroyed and will be recreated every time you swipe. This will lead to huge lag if each of those pages is populating a RecyclerView from a database, etc.
It may be happening because of high resolution image. If you use high resolution images then the viewPager will stuck while swiping . Try using low resolution images.

Can't make Fragment with RecyclerView work

I have to create a list inside one of my Fragments but I cannot make recyclerview work, I was searching the internet whole day followed tutorials but could not figure out why its not working
row_item.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/list"
android:name="com.streak.roadpoliceviolations.ViolationFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
app:layoutManager="LinearLayoutManager"
tools:context="com.streak.roadpoliceviolations.ViolationFragment"
tools:listitem="#layout/fragment_violation" />
Adapter:
public class ViolationAdapter extends RecyclerView.Adapter<ViolationAdapter.MyViewHolder>{
private LayoutInflater inflater;
List<ViolationItem> data= Collections.emptyList();
public ViolationAdapter(List<ViolationItem> data) {
//inflater = LayoutInflater.from(context);
this.data = data;
}
#Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.fragment_violation, parent, false);
MyViewHolder holder = new MyViewHolder(view);
return holder;
}
#Override
public void onBindViewHolder(MyViewHolder holder, int position) {
ViolationItem current = data.get(position);
holder.txt1.setText(current.txt1);
holder.txt2.setText(current.txt2);
}
#Override
public int getItemCount() {
return 0;
}
class MyViewHolder extends RecyclerView.ViewHolder {
TextView txt1;
TextView txt2;
public MyViewHolder(View itemView) {
super(itemView);
txt1= (TextView) itemView.findViewById(R.id.txt1);
txt2= (TextView) itemView.findViewById(R.id.txt2);
}
}
}
Fragment class
public class ViolationFragment extends Fragment {
private ViolationAdapter adapter;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_violation_list, container, false);
RecyclerView rv = (RecyclerView) view.findViewById(R.id.list);
adapter = new ViolationAdapter(getActivity(),getData());
rv.setAdapter(adapter);
rv.setLayoutManager(new LinearLayoutManager(getActivity()));
return view;
}
public static List<ViolationItem> getData() {
List<ViolationItem> data = new ArrayList<>();
String[] txts1 = {"AAA","BBB","CCC"};
String[] txts2 = {"111","222","333"};
for(int i=0; i<=txts1.length; i++) {
ViolationItem c = new ViolationItem();
c.txt1=txts1[i];
c.txt2=txts2[i];
data.add(c);
}
return data;
}
private List<ViolationItem> createList() {
List<ViolationItem> data = new ArrayList<>();
return data;
}
}
Everything passes without a single warning BUT I cannot place this into the fragment container
In mine activity I'm calling the fragment with the following code
//Initial fragment
ViolationFragment frag = new ViolationFragment();
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction() .replace(R.id.frame_container, frag).commit();
Getting this error during the build
Error:(77, 75) error: incompatible types: ViolationFragment cannot be converted to Fragment
And if i change frag initialization Fragment frag = new ViolationFragment();
I get the same error.
How to finally fix this and make the fragment work?!
As I remember you must use support library fragment to make it work. Please check and confirm.

Categories

Resources