List View instance error of cannot find symbol - android

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**);}

Related

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.

search box with fragment does not respond

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");
}

Content has view with id attribute 'android.R.id.list' that is not a ListView class in ListFragment

I am creating a StaggeredGridView using https://github.com/etsy/AndroidStaggeredGrid . But when I try to initialze the StaggeredGridView like follows:-
public class HomeFragment extends ListFragment
{
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View vi = inflater.inflate(R.layout.fragment_home, container, false);
mGridView =(StaggeredGridView)vi.findViewById(R.id.grid_view); // Issue here
return vi;
}
}
This is my Xml file:-
<com.etsy.android.grid.StaggeredGridView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/grid_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:item_margin="8dp"
app:column_count="3" />
I get the following error:-
06-09 09:07:16.568: E/AndroidRuntime(1836): Caused by: java.lang.RuntimeException: Content has view with id attribute 'android.R.id.list' that is not a ListView class
If I change the ListFragment to Fragment I get a NullPointerException while I try to set an adapter
What could be the cause?

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