search box with fragment does not respond - android

Hello I have a problem when I search the page tomorrow the process is successful but when I search the page today there is a problem , I used Fragment
the problem here : https://www.youtube.com/watch?v=FiHGME6i97I&feature=youtu.be
codes :
public void btn_search(View view) {
TextView txtexample = (TextView)findViewById(R.id.txtexample);
txtexample.setText("hello");
}
fragment days
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.user.weather.Fragment_days">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/txtexample"
android:text="#string/hello_blank_fragment" />
</FrameLayout>
fragment days
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_days, container, false);
return v;
}
and fragment today and tomorrow are empty.
please help me , two weeks ago I was looking for a problem

Use the following (note two lines with txtexample):
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_days, container, false);
TextView txtexample = (TextView)v.findViewById(R.id.txtexample);
return v;
}
and
public void btn_search(View view) {
txtexample.setText("hello");
}

Related

List View instance error of cannot find symbol

public class GroupFragment extends Fragment {
private View groupFragmentView;
private ListView list_View;
here i have created instances as well
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
// Inflate the layout for this fragment
groupFragmentView = inflater.inflate(R.layout.fragment_group, container, false);
InitializeFields();
return groupFragmentView;
}
`
private void InitializeFields()
{
list_View = (ListView) groupFragmentView.findViewById(android.R.id.**list_View**);
}}
1 now here im getting error for listView
2 on the left side of equals im having no issue even for the casting there is no error
3 i have tried everything but still couldnt resolve it
4 im still learning android
error showing is-----
error: cannot find symbol
list_View = (ListView) groupFragmentView.findViewById(android.R.id.list_View);
^
symbol: variable list_View
location: class id
`
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".GroupFragment">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent" />
`
You have to pass the object of view in your method.
#Override public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
groupFragmentView=inflater.inflate(R.layout.fragment_group,container,false);
InitializeFields(groupFragmentView);
return groupFragmentView;
}
private void InitializeFields(View view)
{
list_View = (ListView) view.findViewById(android.R.id.**list_View**);}

Unable to Position Bottom Sheet Dialog at the bottom of the screen

I have a Video Detail Fragment which I want to behave as a bottom sheet behaviour, but unfortunately, the dialog is getting displayed at the centre of the screen. I am unable to figure out the exact problem in the code. Below I am attaching the code and the layout file, in regard to the same.
This is my Video Detail fragment:
public class VideoDetailsFragment extends BottomSheetDialogFragment {
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AppCompatDialog dialog = new AppCompatDialog(getActivity());
dialog.setTitle(titleId);
return dialog;
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View dialogView = inflater.inflate(R.layout.video_detail_fragment, container, false);
Button cancelButton = dialogView.findViewById(R.id.track_selection_dialog_cancel_button);
Button okButton = dialogView.findViewById(R.id.track_selection_dialog_ok_button);
return dialogView;
}
public static final class TrackSelectionViewFragment extends BottomSheetDialogFragment
implements TrackSelectionView.TrackSelectionListener {
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.exo_track_selection_dialog, container, /* attachToRoot= */ false);
TrackSelectionView trackSelectionView = rootView.findViewById(R.id.exo_track_selection_view);
trackSelectionView.setShowDisableOption(true);
trackSelectionView.setAllowMultipleOverrides(allowMultipleOverrides);
trackSelectionView.setAllowAdaptiveSelections(allowAdaptiveSelections);
trackSelectionView.init(mappedTrackInfo, rendererIndex, isDisabled, overrides, /* listener= */ this);
return rootView;
}
}
}
The xml file for video_detail_fragment:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="270dp"
android:visibility="visible"
app:behavior_hideable="true"
app:behavior_peekHeight="0dp"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
>
<FrameLayout
android:id="#+id/child_fragment_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end">
</LinearLayout>
</LinearLayout>
I went through many posts but almost all the posts were showing the solution as setting the app attribute app:layout_behavior="android.support.design.widget.BottomSheetBehavior". But it's not working in my case. Kindly help me understand as to where I am doing wrong?

I need to inflate a RecyclerView inside a Fragment AndroidStudio

I would like to use a Tab/Fragment to show RecyclerView, but I don't know how to do it because the method of the Fragment class return a View, not a Reclycler View:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
myFragmentView = inflater.inflate(R.layout.fragment_needs, container, false);
return myFragmentView;
}
The code of the fragment.xml is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".NeedsFragment">
<FrameLayout
android:id="#+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="0dp">
<android.support.v7.widget.RecyclerView
android:id="#+id/all_user_need_list"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</FrameLayout>
</RelativeLayout>
Thank u.
First off, your onCreateView() method makes no sense:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
myFragmentView = inflater.inflate(R.layout.fragment_needs, container, false);
return needsFragmentRecyclerView; //you should be returning myFragmentView here, not whatever needsFragmentRecyclerView is
}
Second, once you inflate your layout, just use findViewById():
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
myFragmentView = inflater.inflate(R.layout.fragment_needs, container, false);
RecyclerView recyclerView = myFragmentView.findViewById(R.id.all_user_need_list); //assign to a global variable if needed
return myFragmentView; //replaced with the proper variable
}
Alternatively, you can get the RecyclerView from anywhere in your Fragment, as long as it's called after onCreateView() with the following:
RecyclerView recyclerView = getView().findViewById(R.id.all_user_need_list);
You can return any type of view component and Custom view that is inherit from android.view class in onCreateView() method.

Android: Fragment showing from old fragment

I have two fragments on top of each other when I call the second fragment I still the buttons from the first fragment stay visible and functional.
I tried many many methods but didn't work
This one gave me this error:
java.lang.IllegalArgumentException: No view found for id 0x7f0e0004 (*.test:id/customId) for fragment SecondFragment{adef947 #0 id=0x7f0e0004}
and This
java.lang.IllegalArgumentException: No view found for id 0x7f0e00ae (sy.aya.ayaisp.test:id/gatesViewpager) for fragment SecondSFragment{adef947 #0 id=0x7f0e00ae}
my code is as follows:
FirstFragment.java
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
View myView = inflater.inflate(R.layout.first_fragment, container, false);
Button FBtn = (Button) myView.findViewById(R.id.Fbutton);
FBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Bundle bundle = new Bundle();
bundle.putString("second", "f button");
SecondFragment secondFragment = new secondFragment();
secondFragment.setArguments(bundle);
FragmentTransaction ft = getChildFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.slide_in_up, R.anim.slide_in_up);
ft.replace(R.id.s_con, secondFragment).addToBackStack("back").commit();
}
});
SecondFrag.java
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
String bundleString = this.getArguments().getString("second");
View view = inflater.inflate(R.layout.s_rv, container, false);
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.s_recyclerview);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
if (bundleString == "agents button") {
recyclerView.setAdapter(new SecondAdapter(getContext()));
}
}
first_fragment.xml
<android.support.constraint.ConstraintLayout 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/s_con"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/Fbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="secondFragment"/>
</android.support.constraint.ConstraintLayout>
s_rv.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<sy.aya.ayaisp.ExpandableRecyclerView
android:id="#+id/s_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:clipToPadding="false"
android:scrollbars="vertical" />
</FrameLayout>
Thank you for your help
In second fragment layout "s_rv" in root element of xml add some background, clickable="true" and focusable="true".
And in first fragment layout wrap your button in LinearLayout. two days back I was also facing same issue it was solved after that.
It is because in your first fragment the id of button is "pos_agents_button" but in findViewById you are trying to find "R.id.Fbutton".
Change
Button FBtn = (Button) myView.findViewById(R.id.Fbutton);
to
Button FBtn = (Button) myView.findViewById(R.id.pos_agents_button);
and everything should work fine.

Fragment is not showing up

I m trying to make a simple fragment example where one fragment will show an Article List and the other will show detailed article.
This is my main activity class-
public class ArticleFragment extends Activity{
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}// end class
This is the main layout file-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment android:name="com.example.ArticleList"
android:id="#+id/list"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />
<fragment android:name="com.example.ArticleDetails"
android:id="#+id/viewer"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="match_parent" />
</LinearLayout>
This is my two fragment class for ArticleList and ArticleDetails
public class ArticleList extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.articlelist, container, false);
}
public class ArticleDetails extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.articledetails, container, false);
}
}
I have also TWO XML layout files(containing a textview) for both articleList, ArticleDetails fragment. But the app has stopped working. What have I missed here? Pls help thanx.
Check your Package name inside the code
<fragment android:name="com.abc.def............./>
.Thanks to you I know that we can do it.

Categories

Resources