FAQ Database Discussion Community


Fragment's onCreate and onCreateView are not called

android,android-fragments
I'm building an application which receive an action.SEND Intent and display all files in clip data into a ListView. My ListView is inside a ShareFragment which hosted by my MainActiviy. Below is how i implement it. public class ShareFragment extends MFragment { private static final String TAG = "ShareFragment"; private...

Load Maps within Fragment

android,google-maps,android-fragments,supportmapfragment
I am developing an app with 2 tabs on swipe, each one loading its Fragment. The first of them is a ListFragment (which it's ok), and the second should load a map, but when I tried to insert Google Map into this Fragment, it crashes the application and displays the...

Android layout design: composite Relative vs fragments

android,android-layout,listview,android-fragments,android-listfragment
I want a simple scrollable ListView. I have a custom adapter that makes each row display a picture and some text. Underneath I want a few buttons. I'm looking for a layout like this sample picture: This seems like it should be trivial. I have a single main activity that...

How can i access fragment layout in parent activity?

java,android,android-fragments,gridview,baseadapter
I have got a tabpager and fragments. And a frament has got a "GridView". I am using a basedapter innerclass in the fragment parent activity. But when i want to set adapter to my gridview i m getting nullpointerexception. Because GridView variable is always null.how can solve this issue? Fragment...

How can I set the visibility for a xml element inside a fragment created via pager adapter?

java,android,android-fragments,android-viewpager
I have this activity that instantiates 5 different fragments that represents passengers and add them to a view pager in tabs. Each of those inflates the same xml file. What I want to do is be able to set the visibility for some of the xml fields in each of...

Adding Icons to Navigation Drawer

android,android-fragments,android-activity
I am trying to add Icons to my NavigationDrawer. strings.xml <string-array name="nav_drawer_icons"> <item>@drawable/ic_action</item> </string-array> FragmentDrawer.java private static Integer[] icons = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // drawer labels icons = getActivity().getResources().getIntArray(R.array.nav_drawer_icons); } In my code above, I'm trying to load the xml's array to icons' array, but...

Android parentActivity not getting recreated after startActivityForResult returns

android,android-intent,android-fragments,android-activity
I have a MainActivity and inside it, I am loading a fragment A. From FragmentA , I am calling google placepicker activity using startActivityforResult as follows. PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder(); Intent intent = builder.build(getActivity()); getActivity().startActivityForResult(intent,PLACE_PICKER_REQUEST); But when I select place, onActivityResult(either in FragmentA or MainActivity) is not getting called....

RecyclerView in FragmentPagerAdaper only updates when screen is rotated

android,android-fragments,recyclerview,fragmentpageradapter
I have a fragment in a FragmentPagerAdpater. The Fragment is basically a RecyclerView. The source for the RecyclerView is provided by a Loader which is inside the Fragment. My problem is that the list appears empty when it is first instantiated. But when I rotate the screen, it appears fine....

Explanation of Fragment lifecycle and how to access it

android,android-fragments
I am fairly new to Android and am trying to understand how to access - for testing purposes - various components. I have a Settings app that has, for example, "wi-fi", "Bluetooth", "display", and "language." Each of these buttons will open, on the right hand side of the screen, a...

How to Know What Part of a TextView was Selected

android,android-fragments,textview,onclicklistener
I am populating textviews on the activity dynamically, based on text that is being parsed in from xml articles. The text is formatted using html tags, so I set the text like: textViewBody.setText(Html.fromHtml(content)); The articles are set up to either some text in a body to a website, to another...

Return to same Fragment on backPressed

android,android-fragments
I have implemented a ´NavigationView´ which has a few menu options that when user selects one, it changes the "main fragment" view to anothers... My problem is, I'd like that when the user presses the back button, unless he is on the "main fragment" the screen returns to the "main...

Android: what is the difference between Fragment !isDetached() and isAdded()?

android,android-fragments
In my Fragment, I want to make a Toast once some data is loaded, like this: Toast.makeText(getActivity(), R.string.toast_loading_done, Toast.LENGTH_SHORT).show(); This only makes sense if the Fragment is still attached to the Activity, i.e. the Fragment is visible and getActivity() will not return null. I could check that with !isDetached() or...

Cannot resolve method 'add(int, com.example.utkarsh.beatle.app.MainActivity.PlaceholderFragment)

android,android-fragments,import
package com.example.utkarsh.beatle.app; import android.app.Fragment; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ListView; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class MainActivity extends FragmentActivity { @Override public void onCreate(Bundle...

How to use a MediaPlayer Singleton

java,android,android-fragments,media-player,android-mediaplayer
I am new to Android developing and am starting with a simple soundboard application. I started developing a soundboard using multiple fragments until I realized that I was using multiple instances of MediaPlayer. This is not good because I want only one sound to play at a time. I realized...

Adding a fragment to android.R.id.content enables clicks on background fragment

android,android-fragments
I've and Android Application. I want to display a fragment in the bottom of the screen on top of everything (like a dialog, but in the bottom). I'm adding a fragment to android.R.id.content: FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction(); transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); transaction.add(android.R.id.content, new MyFragment()).addToBackStack(null).commit(); The fragment is displayed, but the views that are...

list view in fragments null pointer exception

java,android,android-fragments,android-listview,swiperefreshlayout
I am trying to setup swipe to refresh in my fragment, which fetches objects from parse. But every time, I seem to get an null pointer exception on setadapter and list view. Although both of them are correctly initialized are not null. My recentsadapter: package com.astuetz.viewpager.extensions.sample; import android.content.Context; import android.view.LayoutInflater;...

How to access controls(views)in tabs from another one in android?

android,eclipse,android-fragments,android-tabs,oncreate
i'm working on application in eclipse that have 5 tab and i have spent much time for that but now i have a big problem : when one of tabs is activated the next tab and prev tab is loading too and onCreated() method is called but i don't need...

How to get the Data from DialogFragment to MainActivity in Android?

java,android,android-fragments
I create a application using DialogFragment.I want to get the Data from DialogFragment and setText in the MainActivity. In my Code I successfully Created the AlertDialog.But I con't able to get the EditText value to MainActivity.Application is crashed.Please help me to solve the problem.Any Help would be I really Appreciate....

Android variable never used [duplicate]

java,android,android-fragments,android-activity
This question already has an answer here: What does the “Assigned value is never used” warning mean? 5 answers After creating my activity, I get this warning: Variable 'station' is never used I not certain as to what that warning means nor how to fix it. I'm guessing the...

Good approach to clean application data programmmatically in Android

android,android-fragments,memory,android-activity,picasso
When I use RecyclerView and/or Picasso. It seems to cache and store alot of data in my application. However, I want to delete the stored data and the cache in a simple way whenever I am exiting my app. What is the simplest way to delete all data stored in...

Update Action Bar Style Using Theme AppCompat Light

android,android-layout,android-fragments
I am trying following in style file but unable to change font and text position of action bar. I want to do it in my style sheet. <resources> <!-- Base application theme. --> <!-- Theme.AppCompat.Light.NoActionBar, Theme.Holo.Light --> <style name="AppTheme" parent="Theme.AppCompat.Light"> <!-- Customize your theme here. --> <item name="android:windowBackground">@color/white</item> <item name="colorPrimary">@color/green</item>...

Proper replacing fragments

android,android-fragments
Hi I'm wondering what is the proper way to change fragment, add them to backstack, and restore visibile fragment after screen rotation. Currently to initialize first fragment I use this method: private void inflateInitialFragment() { FragmentManager manager = getFragmentManager(); Fragment mainFragment = manager.findFragmentByTag(MainMenuFragment.class.getSimpleName()); FragmentTransaction ft = manager.beginTransaction(); if (mainFragment ==...

I want to extend Fragment and Activity in one class to use navigational drawer for an activity without changing my overall code

java,android,android-fragments,android-activity
This is my one of my fragment activity among three. All I want to do is use functions from Activity class(ie use setContentView(), startActivity()etc). Please don't worry about the package name of the project which I deleted for some reasons. Thanks in advance! import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import...

How to call a fragment from a fragment

android,listview,android-fragments
I am making an application. In this application, I have a fragment that contains a listView. When I click on any item it should start a new fragment which displays the item website. My listView fragment code : public class MyFragment extends Fragment { private ListView mListViewASSociation; private ListViewAssociationAdapter mListViewAssociationAdapter;...

Need up to date way to implement activity with tabs connect to fragments? while ActionBar.TabListener is deprecated, TabLayout can't be resolved

android,android-fragments,android-activity,android-tabs
I need activity with multiple tabs that connect to fragments. I have found using ActionBar.TabListener, however, it is depreciated in API Level 21. Also, when using TabLayout, Android Studio tells me it can't resolve it!! Can anyone suggest a more up to date way to do this?...

Is it possible to use common fragment generate function globally?

java,android,android-fragments,global
I have common fragment generate function like the following: // Common Fragment generation method public void generateFragment(String speechString, String buttonString) { // Store data to be passed to the fragment in bundle format Bundle args = new Bundle(); args.putString("Speech", speechString); args.putString("ButtonTitle", buttonString); // Instantiate Speech fragment and set arguments SpeechFragment...

Clicking CardView to load a fragment

android,android-fragments,recyclerview,android-cardview
I'm having trouble with implementing clickable cards with my RecyclerView. I want to get the position of which card was clicked and then load the proper fragment. I did take a look at this post and spent almost 30 minutes trying to make sense of the code and implementing it...

Android switch Fragments in the new design support navigation drawer

android,android-fragments,navigation-drawer,androiddesignsupport
how can I switch Fragments in the new design support navigation drawer? I found example codes on the Cheesesquare Github on how to switch fragments using the TabLayout, but not the navigation drawer. Is that the same? I also would not like to recreate fragments when switching, but rather do...

Load Google Maps in a tab when tab is picked, and not from begining

java,android,google-maps,android-fragments,tabs
I have a TabLayout with 2 tabs. First tab ( Main tab ) is a list of store in a listview Second tab is the same list in a Google Maps. I noticed that When I go by default in the first tab ( list ), the GPS icon appears...

Dealing with Fragment and listView and JSON

android,android-layout,android-intent,android-fragments,android-activity
I am trying to make an application with MenuDrawer that contains 4 fragments. This is how my application show do. When it starts, it should retrieve data from a website. The retrieved data should be in a listview in the first fragment. The second fragment should contain a webview to...

How to download a file on a click

android,android-fragments
how are you doing ? I am making a application, in the application I want to click a listView and my application starts to download a link. I already have the link. I used the following code but, my application crashes: Here is the listener to handle my clicks: mListViewMagazine.setOnItemClickListener(new...

Fragments addToBackStack Closing the application

android,android-fragments,fragment,options-menu
I am calling some fragments from HomeScreen.java. Now whenever i press back button in any fragment, its closes the application. But i want previous fragment which was loaded.Following is HomeScreen.java code. public class HomeScreen extends AppCompatActivity implements JobListFragment.OnJobSelectedListener { Timer timer; TimerTask timerTask; final android.os.Handler handler = new android.os.Handler(); FragmentTransaction...

java.lang.NoClassDefFoundError: While calling fragment

java,android,android-fragments,noclassdeffounderror
I am trying to use SherlockFragment to create a Fragment, selected from a navigation drawer activity to show a tabbed fragment. My main activity is below: package com.impact.main; import com.impact.main.R; import com.impact.adapters.NavDrawerListAdapter; import com.impact.helper.SQLiteHandler; import com.impact.helper.SessionManager; import com.impact.helper.dbTables; import com.impact.model.NavDrawerItem; import java.util.ArrayList; import com.actionbarsherlock.app.SherlockFragment; import com.google.android.gms.gcm.GoogleCloudMessaging;...

How to get data from SimpleDialogFragment to a Fragment?

java,android,android-fragments,dialogfragment,simpledialog
I have a main class: public class MainFragment extends Fragment implements OnClickListener, OnMarkerClickListener {} I have a dialog class: public class PedirTaxiDialog extends SimpleDialogFragment implements OnClickListener{} For example: I have FragmentA from which I start SimpleDialogFragment (there are EditText in box). How to can I get back the value from...

Fixed element in android?

android,xml,android-fragments
I am using a FAB(Floating action button) and a ViewPager that has a list inside a fragment. The ViewPager stops due to the FAB block and each are blocks the ViewPager being on top of the FAB activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:fab="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:fitsSystemWindows="true">...

Adapter ListView not refreshing from Activity

android,listview,android-fragments,android-arrayadapter
I am trying to refresh the contents of my Fragment's ListView ... based on the results I receive in my Activity. What I want - To load contents of 'artistsName' List (present in my Activity) into the ListView of my Fragment What is the problem - Despite calling notifyDataSetChanged() on...

Contexts and callbacks from asynchronous tasks

android,android-fragments,asynchronous
I've been experiencing this problem on some devices, especially Samsung. I have an activity that has 7 fragments. In most of them, I start an async task for getting some data. I handle the exceptions by creating a handler in onCreateView(). handler = new Handler(new Handler.Callback() { @Override public boolean...

Fragment Memory Leak

android,android-fragments,fragment,android-memory
I have 4 fragments in my android app. I have a FragmentPagerAdapter to fill the ViewPager. Also I'm extending FragmentActivity in main activity. The problem is when I slide in fragments, other fragments are destroying(by garbage collector?). How can I avoid this? FragmentAdapter: package com.quiz.Adapter; public class FragmentAdapter extends FragmentPagerAdapter...

Hide Parent Fragment from the Fragment in the viewPager

android,listview,android-fragments,android-viewpager
I have a Fragment A holds a view pager that display serval nested fragments. B and C are the fragments directly hold by the view pager. And each B and C holds a listView. When click listView item fragment D will show up. The problem is that, I could only...

Fragment AsyncTask not executing after back button pressed

android,android-fragments,android-asynctask
My program is structured as follows from a navigation standpoint: Fragment A -> Fragment B -> Fragment C (back button pressed) -> Fragment A I have an async task that normally fires in onActivityCreated in Fragment A: fetch = new FetchVenues(this, user); fetch.execute(); After navigating to other fragments, I handle...

Return a String from a Thread Android Java

java,android,multithreading,android-fragments,android-intent
I am using a Thread to perform an HttpURLConnection and get data from my database. The code below represents what I would like to accomplish but I get an error on the line str_Data = "John Doe"; Error: Variable 'str_Data' is accessed from within inner class public void onCreate(Bundle savedInstanceState){...

Problems with implementing contextual action mode in recyclerview fragment

android,android-fragments,recyclerview,android-actionmode
I hacked together my first app from a bunch of tutorials. With the help of one of them I implemented a RecyclerView inside a fragment which is used by the main activity. Now I found another tutorial which I want to use to implement multi-selection with the contextual action mode....

How to simple deal with progress dialog with AsyncTask and fragment?

android,android-fragments,android-asynctask
I want to use a ProgressDialog within a Fragment for an AsyncTask. With Activity the following code works perfectly, but with Fragment no. public class ResultTask extends AsyncTask<String, Void, Report> { private ProgressDialog pDialog; private Context context; public ResultTask(Context context) { super(); this.context = context; } @Override protected void onPreExecute()...

android - No Activity found to handle intent action.VIEW

android,exception,android-intent,android-fragments,textview
I got an exception in my android app: 06-18 17:57:39.816 6333-6333/com.appsrox.instachat E/InputEventReceiver﹕ Exception dispatching input event. 06-18 17:57:39.816 6333-6333/com.appsrox.instachat E/MessageQueue-JNI﹕ Exception in MessageQueue callback: handleReceiveCallback 06-18 17:57:39.816 6333-6333/com.appsrox.instachat E/MessageQueue-JNI﹕ android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=href (has extras) } at...

Fragment not appearing properly in two pane tablet mode

java,android,xml,android-layout,android-fragments
I'm trying to launch my fragment in the detail fragment & highlight the selected list item (code is there in FragmentWCLine.java) in two pane mode but for some reason it won't do so. Seems to work fine in single pane mode but when it comes to two pane mode it...

Having problems to implement a setOnClickListener - Fragment

android,android-fragments,android-listview
I'm having problems to implement an onclick to the items I have in my list. the error is below: 06-14 16:15:43.861 11651-11651/wk.gon250.dublinbike E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: wk.gon250.dublinbike, PID: 11651 java.lang.RuntimeException: Don't call setOnClickListener for an AdapterView. You probably want setOnItemClickListener instead at android.widget.AdapterView.setOnClickListener(AdapterView.java:778) at tab.Tab2.onCreateView(Tab2.java:67) The code of my...

Integrating Localytics - FragmentActivity

java,android,android-fragments
Trying to integrate Localytics, step 6 assumes you extend FragmentActivity: In onResume, open a session, start an upload, and register the activity for marketing. public void onResume() { super.onResume(); Localytics.openSession(); Localytics.upload(); if (activity instanceof FragmentActivity) { Localytics.setInAppMessageDisplayActivity((FragmentActivity) activity); } Localytics.handleTestMode(activity.getIntent()); } In my class, MainActivity.java, we're extending a class that...

Using maps on api 21+ inside of tab

android,google-maps,android-fragments
I am just working on an application trying to learn a lot of the newer technology with API 21 / API 22. I am relatively new to android In general, but just want to make sure I am doing everything the up to date way. In my app I have...

Unable to start activity from main activity which contains fragment

android,android-fragments
I am trying to use fragment and also start an activity in a method in MainActivity. My code MainActiviy.java is: protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Setting up toolbar here toolbar = (Toolbar) findViewById(R.id.app_bar); toolbar.setLogo(R.mipmap.ic_launcher); toolbar.setTitle(" Daily Qura'n Verses"); setSupportActionBar(toolbar); // add tabs in the mainactivity super.onPostResume(); mTabHost...

Android XML id within fragment collection [email protected]:id' gives cannot resolve symbol error.

android,xml,android-fragments
I'm new. I have an XML for fragment collection object. In I have two text views that work perfectly. When I try to add another in the exact same format receiving can't resolve error. (ie: android:id="@android:id/tvNewText"). If I add an id like a regular XML (ie: android:id="@+id/tvAnotherNewText") I cannot access...

“Activity has been destroyed” error on Fragment testing with Robolectric

android,android-fragments,robolectric
I'm trying to make Fragment testing on Android with Robolectric and I know there's been some other posts about problems with FragmentActivity when it hasn't been stored in some variable. However, I was trying to make this post work and you can see in this case the FragmentActivity object reference...

Accessing shared preferences in a non-activity class from fragment class

java,android,android-layout,android-fragments
I have a fragment: public class TodayVerse extends Fragment { TextView textView; DailyQuranMethods dailyQuranMethods; public TodayVerse() { // Required empty public constructor } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_today_verse, container, false); textView = (TextView) view.findViewById(R.id.verse);...

Android Fragment Layout Listeners

java,android-fragments,onclicklistener
I have code that inflates particular fragments based on user choices. I want to set an onCliclListener to a button in a particular fragment layout but I don't know which java file to do so in. I assume it's the fragment java file but I can't initialize the button. Here...

Reset all Views in fragment

android,android-fragments,android-viewpager,android-view
So I am currently in FragmentA.java, a class which consists of different EditTexts and Checkboxes for users to press and input. My question is, I have this reset button, how can I reset the entire fragment view? (e.g. an EditText will be set to empty string, or with the value...

how to reuse common fragment views in other fragment class?

android,android-fragments
I created a GridView menu in my FragmentA class and also i created a separate Common_Fragment class which is contain two ImageView Now i want to reuse those Common_Fragment views in my FragmentA class and other Fragment.. how can i do this please help me it's very urgent..... My FragmentA...

Unable to instantiate fragment make sure class name exists

java,android,android-fragments
android.app.Fragment$InstantiationException: Unable to instantiate fragment: make sure class name exists, is public, and has a empty constructor that is public. I realize there are many questions posted regarding the same error, but none have helped me so far. I am learning from a book, and have actually run the exact(99%...

Unable to use string resources for list view items

java,android,android-fragments,android-listview,android-listfragment
I'm trying to use string resources for my 2-line list view items rather than hard-coding them but I get this error. How can I fix that? Before using string resources public class ListData { public static final String[][] items = { {"America","America Description"}, {"Europe","Europe Description"}, }; } After using string...

Spinner height expands to bottom of screen

android,android-layout,android-fragments
I have a fragment with a spinner in a layout. The spinner xml is: <Spinner android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/spCategory" android:spinnerMode="dialog" android:dropDownWidth="match_parent" android:prompt="@string/label_category_select" /> Populating the spinner is done like this: List<Category> categories = categoryRepository.getAll(); CategoryAdapter adapter = new CategoryAdapter(this.getActivity(), categories);...

Have a fragment re-load on post execute

android,android-fragments,android-asynctask
I have a fragment which calls an async task. When the async task is done I want the fragment to completely re-load. Basically, my fragment loads a random review. The user then rates the review with a star bar at the bottom. When they click the star bar a async...

Having problems while trying to delete single rows from a custom ToDo list?

android,android-fragments,checkbox,android-studio
I want to delete selected rows from a todo list by clicking on the checkbox and deleting them trough the delete button, for that I am within my custom adapter setting a setOnCheckedChangeListener on my checkbox and setOnClickListener on my delete button, now keep in mind that the delete button...

How to call a fragment using a dialog

android,android-fragments,android-activity
I have a dialog extended class. I want to call a fragment to be displayed on a click of a button. I am using this method: public void onClick(View v) { dismiss(); SearchingFragment mySearchengine = new SearchingFragment(); FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.content_frame, mySearchengine); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); }...

Can't Open Fragment when clicked button

java,android,xml,android-layout,android-fragments
I have created 2 fragment and their layout, when i click button on profile fragment it should open flat layout, but it force stop application and its not opening the second fragment, i have included fragment code and its layout code.. profilefragment.java public class ProfileFragment extends Fragment { View rootView;...

Android set clickable text to go one fragment to another fragment

java,android,android-fragments,spannablestring
I need to do something like this. Suppose I have 2 fragments A and B.There is a text which can be clickable in fragment A and when user click this text , he can go to fragment B. This example helped me to do it but I think it does...

Android : How to control progressbar (which is in action bar of acivity) from other fragment?

android,android-fragments
I have created NavigationDrawer app. On each item there is a WebView. I have added ProgessBar in ActionBar using following code. requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); My problem is I want to show ProgressBar (in ActionBar) when page from Fragment starts loading and hide ProgressBar(in ActionBar) when page loading is finished. Below is my...

Interaction between fragments slow refresh

android,android-fragments,android-viewpager
On my screen I have 2 containers - left for 3 fragments in view pager, right for single fragment. From this on the right I increment some temp variable and through inteface I pass this variable to fragments. I switch fragments in view pager and everything seems to act all...

How To Make More Than Two buttons in Fragment to Open Different Activity

android,android-fragments,android-activity,android-fragmentactivity
I have Created 3 Activities and their class, i want to open them when button pressed, And buttons are in Fragment, i have successfully implemented this For A Single Button, and works. But I Want To do same thing for both button, How Can i make both button to open...

Null Pointer Exception

android,android-fragments
I'm getting the following error: 6-15 19:57:50.291 9743-9743/com.example.utkarsh.beatle.app E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.NullPointerException at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:392) at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362) at android.widget.AbsListView.obtainView(AbsListView.java:2214) at android.widget.ListView.makeAndAddView(ListView.java:1852) at android.widget.ListView.fillDown(ListView.java:678) at...

populating a text view in an android Fragment from a text file in /res/raw

java,android,android-fragments,android-studio
I am attempting to populate an textview in an android fragment. I am having no luck at all as the fragment is blank. I know I am fundamentally missing something. I have read the docs on fragments and I am still confused. Below is my code for one of the...

DialogFragment callback to Target Fragment using interface

android,android-fragments,interface,callback,android-dialogfragment
I am trying to send some data from a dialogfragment to the targeted fragment but its not working. I have written the following code, but it through exception: java.lang.NullPointerException: Attempt to invoke interface method 'void com.x.x.FragmentAlertDialog$Communicator.setI(java.lang.String)' on a null object reference Code: public class FragmentAlertDialog extends DialogFragment { Communicator callback;...

Dagger 2 Custom Scope for each Fragment

android,android-fragments,dagger-2
I'm a little confused about how to best use the custom scoping in Dagger 2. I've looked at a couple different articles which seem to suggest two different ways of doing it: MVP Presenters that Survive Configuration Changes Part-2 (Github repo): Uses unique custom scopes for each fragment, e.g. @Hello1Scope...

FIndFragmentByTag fails after orientation change

android,android-fragments
I'm trying to use an UIless retained Fragment not to lose Service Binders during orientation change. The problem is that in the Activity onCreate the findFragmentByTag always returns null. This is my activity: public abstract class AbstractLearnActivity extends Activity implements FragmentCallbacks { private final static String BINDER_FRAG_TAG = "AbstractLearnActivity.BINDER_FRAG_TAG"; private...

fragment is already active while calling Fragment.setArguments()

android,android-fragments
I am creating an activity which shows a list of videos(VideoListingActivity) depending on the parameters passed from the parent activity.my I am trying to pass the bundle passed to VideoListingActivity to its child fragment so that it can fetch the related data from database and display it on the activity....

How To Update a layout in onActivityCreated() of Fragment

android,android-layout,android-fragments,android-activity
I am inflating a layout in onCreateView() of the Fragment,On the Activity created() of the Fragment,I am retreving the data from the DataBase and updating the values in the layout from the DataBase which i inflated earlier. LinearLayout main = null; if (rootView instanceof LinearLayout) main = (LinearLayout) rootView; main.removeAllViews();...

Android Google Map - Error inflating class fragment

java,android,android-fragments,android-fragmentactivity,google-maps-api-2
I am trying to show GoogleMap on my Activity. I have done all necessary steps including key generation, linked google-play-services_lib, added android-support-v4.jar. But I am facing an error because of Fragment. I have tried many solutions, spent many hours but unable to solve this problem. Please help me. MapActivity.java package...

how do i check if the edit text view contains 2 white spaces?

android,android-fragments,android-edittext,android-view,android-textview
Currently my edit text view checks if the searched term contains one space as follows: if(mSearchView.getText().toString().contains(" ") How do I make it such that it makes sure it checks if the searchview contains 2 spaces between 3 search terms for example: "here it is"...

ViewPager not showing page content / not refreshing after changing the view

android,android-layout,android-fragments,android-viewpager
I am using ViewPager / FragmentPagerAdapter in one of my application fragments to display different listviews in each page (see the picture below) : The problem is that after i change the current view (Fragment) and i reopen it again, the listview isn't rendered (see the picture below) : The...

how to call RecyclerView in the first fragment of the navigation drawer? I've followed a tutorial by slidenerd but getting one error

android,android-fragments,android-navigation,android-recyclerview
This is the Java file of the fragment I wish to insert recycler view. Please dont worry about the package name which I deleted for some reasons. import android.app.Activity; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import java.util.ArrayList; import java.util.List; public class Dashboard...

How to start an activity from an image button which is there in a fragment of a navigation drawer

android,android-fragments,imagebutton
I'm have implemented a navigation drawer with fragments, now I'm trying to open an activity from those fragments. There are too many fragments I'm posting one of them over here i.e About us, I just wanna start an activity or a fragment (whichever is more simple) on click of the...

Sound control in android fragment

android,android-fragments,android-mediaplayer
If I add two Fragment to one Activity, each playing different media, is there a way to mute the sound coming from one Fragment while the other plays full volume? From my research, it seems you can only control the devices volume with code, thus if two media are playing,...

Getting particular view from expandable listview

java,android,listview,android-fragments,expandablelistview
In my list view I have an textview in expandable group and I want to open the dialog when textview is clicked to fill the information through edittext and update textview. Problem: how could I get the groupview textview item in my fragment oncreateview() method....

Difference between “binding” and “attaching” in android

android,android-fragments
Android beginner here. I've seen both the term "attach" and "bind" in many places in the documentation, and they both sound very similar. What is the difference? I know the fragment class has an onAttach method that is called early in their lifecycle. What does this do, exactly? Does it...

Getting arguments from a bundle

android,android-intent,android-fragments
I'm trying to pass arguments from my Activity to a Fragment and I'm using this code: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_detail); String message = getIntent().getStringExtra(Intent.EXTRA_TEXT); DetailActivityFragment fragment = new DetailActivityFragment(); Bundle bundle = new Bundle(); bundle.putString(INTENT_EXTRA, message); fragment.setArguments(bundle); } I'm getting the value of the message variable...

Show animations on every viewpager change

android,android-fragments,layout-inflater
I want to show animations on every content of layout inflater. Below is the code that I am using but the problem is animations shows only on first page of view pager. What I have understood so far is that animations on all pages content gets loaded on position 0...

AppCompatActivity with normal fragments and support fragments

android,android-fragments,android-activity
I am using the latest AppCompatActivity (android.support.v7.app) and in the MainActivity, I am using the normal Fragment(android.app.Fragment) and getFragmentManager(instead of getSupportFragmentManager). Anyone aware of any problems if we mix Fragments from support library? I am facing some weird behavior in my application as posted in below question? Android parentActivity not...

Using Tabs inside android.app.Fragment?

android,android-fragments,android-tabs
How can I create a Fragment with tabs on the top, hosting other Fragments? I previously used android.support.v4.app.Fragment but switched to android.app.Fragment because of the PreferenceFragment class. My code was: public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_tabs,container, false); mTabHost = (FragmentTabHost)rootView.findViewById(android.R.id.tabhost); mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent);...

Android Google Map in FragmentDialog being overlayed by the Dialog's own gray overlay

android,google-maps,android-layout,android-fragments,layout
I just migrated a MapView from an Activity's layout to a DialogFragment. It was a pretty painless migration: A button on the activity launches the dialog, setting the LatLng the map requires: case R.id.btn_open_map: android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); DirectionsMapDialogFragment mapDialogFragment = new DirectionsMapDialogFragment(); mapDialogFragment.setLatLng(mLatLng); mapDialogFragment.setRetainInstance(false); mapDialogFragment.show(fragmentManager, "fragmentName"); break; In the...

How to set app:layout_scrollFlags for Toolbar programmatically

android,android-fragments,android-toolbar,android-coordinatorlayout
My app have a viewpager and 4 tabs, each tab have many fragment. But I just want my Toolbar scroll up/down while scrolling recyclerview in 2 specific tabs. But I don't know how to block Toolbar scroll for other tabs. I tried to import toolbar for each fragment but it...

One AsyncTask for multiple Fragments

android,android-fragments,android-asynctask
I'm Writing an application in Which i have different fragment. In all Fragment i have to use Async Task for fetching data from web server for that i have written a common Async class and implement an interface for getting result but there is casting error i don't know why?...

How to handle multiple fragment interaction listeners in one Activity properly?

java,android,android-fragments,android-activity,android-fragmentmanager
I have one Activity and six different Fragments attached to it. Each fragment has OnFragmentInteractionListener interface and activity implements all these listeners in order to receive callbacks. It looks a little messy, so I'm interested are there some patterns/ways to simplify this and make more elegant?

Difference between preference fragment and “regular” fragment

android,android-layout,android-fragments,robolectric
I am attempting to write some tests to "assert" the headers of my settings app are being properly built. The settings app was built by someone else so I am attempting to understand their code before doing anything. They used "Preference Fragments" in this app. what is the difference between...

android getMenuInflater() in a fragment subclass - cannot resolve method

java,android,android-fragments,android-menu
I am trying to inflate a menu in a class that inherits the Fragment class. Here is my OnCreateOptionsMenu() method - @Override public boolean OnCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.forecastfragment, menu) ; return true; } This raises the following error: Cannot resolve method 'getMenuInflater()' I tried : MenuInflater inflater = getActivity().getMenuInflater(); but...

How to get a list of all views in a fragment?

android,android-fragments,android-view
I would like to get a list of all views inside a main Fragment, so that I could iterate through them in a for loop. Maybe something like this: for (View v : fragmentViews) { ...

Issues with fragments

android,android-fragments,fragmenttransaction,fragmentmanager
I started creating my app with min SDK 15 and I used the v4 support library for the fragments and the fragment manager and fragment transaction etc. When I decided to use card animations, I figured I had to switch to using the fragments without the support library. But when...

Android - No view found for fragment

java,android,android-intent,android-fragments,android-activity
I'm trying to get my replaced fragment to appear in the detail fragment but after debugging my app on a tablet emulator and selecting the necessary list view item, the log cat gives me this error: Caused by: java.lang.IllegalArgumentException: No view found for id 0x7f0c0050 (com.apptacularapps.exitsexpertlondonlite:id/detail_container) for fragment FragmentWCBank{3b4ea8fb #0...

Android replace fragment from one to another is not working

android,android-fragments,android-fragmentmanager
I am trying to open a fragment on button click. Button click is already in a fragment. So what I trying to do is to open a fragment from another fragment. I google it thoroughly and found this code FragmentInner_Add_Location fragment = new FragmentInner_Add_Location(); FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.fragment_container, fragment);...

OnClickListener called after fragment detach

android,android-fragments
I've some rare crash reports of a live app, with OnClickListener of a Gridview being called after the destruction of its parent fragment. Here's a MCVE of the situation: public class MyFragment extends Fragment { private Activity activity; @Override public void onAttach(Activity activity) { super.onAttach(); this.activity = activity; } @Override...

Android TabLayout (API 22) add fragment to each tab without ViewPager

android,android-fragments
I'm trying out Android's new TabLayout class to add two tabs just below my ActionBar. Each tab will host a different fragment. Also, I don't want to be able to swipe between my two tabs - to navigate between my tabs, I'd like to be able to ONLY touch the...

UpButton doesn't work whatever I try to do

android,android-fragments,up-button
In my app (minSdkVersion 15) I have a Toolbar instead of ActionBar and NavigationDrawer switching between fragments. Some fragments have TabBar with child fragments inside. These child fragments are ListViews, and their onItemClickListener triggers DetailFragment. I call setDisplayHomeAsUpEnabled() and an up arrow appears for DetailFragment but I can't treat it...

How to call getFragmentManager on Recycler.Adapter?

android,android-fragments
I am converting ListView of my app to RecyclerView. On ListView, it was very easy to implement OnClickListener but in RecyclerView, we have to do it in adapter. I want to open a new Fragment when user clicks on a item. To do this I have to call FragmentManager in...

A single DialogFragment for multiple dialogs?

android,android-fragments
Can I use one single DialogFragment subclass to display multiple and different (but simple and similar) AlertDialogs? I have many dialogs to display, and I am not sure if creating one class for each of them is necessary and good practice. If I absolutely have to duplicate them: how do...