FAQ Database Discussion Community


What is the purpose of fragment recycling by FragmentManager in Android?

android,fragment,fragmenttransaction,fragmentmanager
I know that Fragment should be created and added to the manager using FragmentTransaction when the fragment is used for the first time. But later it can be found by findFragmentById or findFragmentbyTag after configuration changes such as screen rotation. But on screen rotation, I found that the constructor and...

Passing values between Fragments in FragmentPagerAdapter

android,fragment,fragmentpageradapter
In FragmentPageradapter I have 3 fragments. In first two fragments there is a SeekBar. When either of the SeekBar changes its value in fragment1, I want to change the value ofSeekBar which is inside fragment2. How can I achieve It?

(Viewpager Adapter) getSupportFragmentManager() returns NULL

java,android,fragment
I want to make sliding tabs and here Im stuck : Main.java import android.app.ActionBar; import android.app.ActionBar.Tab; import android.app.ActionBar.TabListener; import android.app.FragmentTransaction; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.support.v7.app.ActionBarActivity; import android.view.Window; public class Main extends ActionBarActivity...

How to add a toolbar in the bottom of the screen?

android,android-activity,fragment,toolbar
I'm new here. I need your help because I don't know some thing. For example, I put a toolbar for my app and not an action bar in the top of the screen...now I want to put a toolbar in the bottom...so how could I do it? Toolbar is the...

Android navigation drawer always open on tablet

android,navigation,fragment,drawer
I have seen many examples around, but I could not understand how to have the navigation drawer, always open in the tablet. I'm using this navigation drawer https://github.com/kanytu/android-material-drawer-template. I will have to create another xml file? and in OnCreate () what kind of code I need to add? public class...

Stop MediaPlayer when Fragment closes

android,fragment,android-mediaplayer
I am using a MediaPlayer inside a Fragment, I have managed to stop the music from playing, whenever the current fragment is changed. But the problem is that, if I was within the fragment, and I press the back button to close the application, the music keeps streaming. My code...

ListView with custom adapter in Fragment

android,listview,android-fragments,fragment,baseadapter
Im trying to use ListView with custom adapter (baseAdapter) in fragmnet. When I us this code directly inside the MainActivity everything works fine, but when I use this in fragment it did't crash but it din't show anything, it is just a blank fragment. Also when I've tried to use...

Android - Changing Fragments within an Activity

android,fragment
I am creating an Android app that uses a main activity, and several fragments. The main activity is the min "control" for everything, and each fragment displays a different screen with different information. Here is some of the code for my main activity: public class MainMenu extends FragmentActivity implements FirstMenu.FragmentListener,...

fragments in viewpager, no view found error

java,android,android-viewpager,fragment,android-nested-fragment
I have an activity holding a fragment, in this fragment there is a button , when it is clicked, a dialog is popped out. In this dialog, there is a Viewpager, which holds some fragments to display. Here are the code and the error, please spare your valuable time to...

How to implement button SetOnClickListener in a fragment?

android,eclipse,android-fragments,fragment,onclicklistener
I'm working on a small project and I want to use a Slider Menu. Long story short I happen to find a source code of a slider menu using drawer from some website and it works very well on my device. However I'm a little bit confused migrating my previous...

Convert an Activity into Fragment for another activity (android)

android,android-activity,fragment,android-fragmentactivity
So I'm having difficulties in understanding how these things work. I have an activity called MapsActivity. Its signature is: package com.ap2.demoapp; import android.app.ActivityManager; import android.location.Location; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesUtil; import com.google.android.gms.common.api.GoogleApiClient; import...

Fragment Transactions with transition - Unique transitionNames are required

android,transactions,fragment,transition,android-transitions
I want to go from a list view to the detail view and therefore, I use following OnClickListener in my list: @Override public void onClick(View view) { Bet bet = (Bet)view.getTag(); FragmentManager fm = getActivity().getSupportFragmentManager(); BetDetailFragment f = BetDetailFragment.create(bet); String tag = f.getClass().getName(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { setSharedElementReturnTransition(TransitionInflater.from(getActivity()).inflateTransition(android.R.transition.move));...

Import text from fragmentactivity to fragment

android,android-studio,fragment,android-fragmentactivity
I want to create a common search for different websites at same time.So I imported text of an EditText from an activity to Fragment activity.Now how to import that text to a fragment? FragmentActivity: public class MyActivity6 extends FragmentActivity { TextView mTextview; ViewPager viewPager = null; @Override protected void onCreate(Bundle...

Click on image inside ArrayAdapter to remove item in listview

android,arraylist,fragment,adapter
I have Fragment... public class MyFragment extends Fragment {... which calls adapter... MyArrayAdapter adapter = new MyArrayAdapter... my.setAdapter(adapter); adapter has image for delete item. I can listen image click but cannot remove item from listview which is in fragment. public class MyArrayAdapter extends ArrayAdapter<String> {... public View getView(final int position,...

How to clear android textedit field

java,android,fragment
I am traing to clear textedit field when it is focused. I know about hint option, but I wanna clear textedit everytime when user actives it, also if is filled by user (now user have to clear field manualy everytime he wants change value). I load fragments in my app...

Android Fragment BaseAdapter not working

android,fragment,baseadapter
This code works correctly in Activity,I change allContexts with getActivity() but when copy it to Fragment after adapter=new ListViewAdapter(getActivity(), arraylist); gets error When mylist.setAdapter(adapter) is running, , my error for class ListViewAdapter How to resolve this? Fragment public class Fragment1 extends Fragment { DataBaseHelper myDbHelper; ListView mylist; ArrayList<String> iran,arr_intityid,arrshomare,primarykeyarrlist; String[]...

How to put viewpager inside fragment in android? [closed]

android,android-viewpager,fragment
I've an activity and I can show some fragments on framelayout on this activity. The problem is that I've viewpager inside one fragment of these fragments and sometimes this viewpager cannot show any thing like its fragments is empty. Could somebody help me?

SaerchView in ActionBar showing icon twice and not getting auto focus. Why is that?

android,android-actionbar,fragment,searchview
I've a SearchView for a fragment in ActionBar. The problem is when I first touch the icon it shifts to the left (Expanded SearchView). Then I have to touch it again to get the text field. The below pics will clarify more. What I have already tried: requestFocusFromTouch(); requestFocus(); setIconifiedByDeafault(false);...

Android. Fix the height of a fragment on all screens

android,fragment,android-linearlayout,relativelayout
I have this xml: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/infoinstalacion_fragment1_relative_imagen_poli" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/Pink"> <ImageView android:id="@+id/infoinstalacion_fragment1_imgfoto" android:layout_width="match_parent" android:layout_height="wrap_content" android:scaleType="fitXY" android:src="@drawable/pol_alza" />...

how to set application context in a fragment in android?

android,list,fragment
i have an ActionBar that has 2 tabs and each tabs layout is a fragment. in 1 of these tabs , there is a listView. and i want to set ArrayAdapetr for it. but when i run app, error occurred and error is about my application context. my code is...

onActivityResult changing my current Fragment

java,android,android-intent,fragment
I am currently having a seemingly odd bug with an application I am writing, this only seems to happen, thus far, on a Samsung S4. It does not happen on an S4 Mini, S5, S6 and Hisense HS-U980. Which is why I am so confused. I am using a Sliding...

android mapfragment programmatically

android,google-maps,fragment,mapfragment
I wish to insert a Android map v2 into a fragment, but my restiction is that I can't use .xml files. The problem appears when I try to instantiate the MapFragment. Here is the code: public class LocationFragment extends Fragment{ private static View view; private static GoogleMap mMap; @Override public...

Activity with fragment who can take two differents fragments and rotation of device

java,android,android-fragments,android-activity,fragment
I'm almost new about android, java, ... and new about fragment. I have an activity (A) that shows a list using fragment (B). Selecting an item of this list, the same fragment is changed to show another lis using fragment (C). It works except when i rotate the device while...

Send a fragment to an activity

android,fragment
Is there a way to send a fragment to an activity? Or is there a better implementation method for my usage? I have a gameOneFrag and gameTwoFrag. For example: From a fragment i want to open one of them in an activity (depending on which button was pressed inside the...

Cannot resolve method 'findViewById(int)'

android,fragment
I am trying to implement a button into a fragment in order to use the soundPool in order to play a sound with a button. At the moment the playSound1 is coming up as never used and I have tried to implement the onClick Method but it is now coming...

How to know which of the fragments launched the current fragment

android,fragment
I launch fragment transition: Fragment fragment = new InstalacionesEncontradasFragment(); Bundle bundle = new Bundle(); bundle.putSerializable("key", this.instalacionesConCategorias); fragment.setArguments(bundle); FragmentManager fragmentManager = getFragmentManager(); InstalacionesEncontradasFragment FragmentTransaction mFragmentTransaction = fragmentManager.beginTransaction(); mFragmentTransaction.addToBackStack(null); mFragmentTransaction.replace(R.id.main_frame_container, fragment, "ACTIVIDADES").commit(); The second...

Passing more than a Bundle to a fragment [Android]

android,fragment,bundle
Is it possible to combine two bundles into one before passing to a fragment on Android? So code snippet would be similar to : Bundle b1 = SomeClass1.getSomeBundle(); Bundle b2 = SomeClass2.getDifferentBundle(); // How to do I pass these two bundles to a fragment? fragment.setArgument(b1 + b2); // Illustrative only....

Fragment with RecyclerView : java.lang.IllegalArgumentException: Scrapped or attached views may not be recycled. isScrap:false isAttached:true

android,fragment,recyclerview
I keep getting java.lang.IllegalArgumentException: Scrapped or attached views may not be recycled. isScrap:false isAttached:true when using Fragment with RecyclerView. I have only 1 Activity which switches between multiple fragments. On activity's onCreate I set the default fragment which happens to have a RecyclerView implemented exactly like in documentation. Upon activity...

Having problems with inserting data into sqlite as new details are replacing all other rows with the newly entered details

android,json,database,sqlite,fragment
im having some problems with my sqlite database, as part of my application i have to save the users favourite deals so i am inserting them into the sqlite database. what happens is that a new row would be created with the details of the new Favorited deal but it...

How to move from a one fragment to an activity

android,fragment
I am working on a CustomListView for a fragment and CustomAdapter extends from BaseAdapter . In my CustomAdapter there is button on click that button i want to move a activity but i don't know how to switch from one fragment to an activity.

Swipe Views with Tabs : Activity or Fragment?

android,android-activity,fragment,android-tabs,swipeview
I'm trying to code a swipe views with tabs (3 tabs). I want each 'page' to be an Activity. I'm using the code in this tutorial, but unfortunately each 'page' there can only be a Fragment. What i tried to do is to transform my Activities into Fragments (but i'm...

Is there a different xml view with “extends Fragment”? [closed]

android,xml,fragment
I'm trying to get my class XML screen but with no success, Until now I was able to create activity, and use startActivity(activity.class) but now there is a problem. At the main Java file of my app i call FTDI class : public void onFTDIClick(View view){ startActivity(new Intent(this,FTDI.class)); } The...

Unreachable statement on imageswitcher

android,fragment,imageswitcher
my code is have a error for unreachable statement on line that have define image switcher public class mainFragment extends Fragment implements ViewSwitcher.ViewFactory{ private OnFragmentInteractionListener mListener; public mainFragment() { // Required empty public constructor } int cnt= 0; int imgs[]={ R.drawable.mah_121, R.drawable.tamashagar_207, R.drawable.tandorosti_149 }; ImageSwitcher imgSwitcher; //final ImageView imageView; //ImageView...

Getting null pointer with recycler adapter

nullpointerexception,fragment,recyclerview,android-recyclerview,recycler-adapter
my app is crashing due to a null pointer with the recyclerview adapter in the fragment code. I'm using this adapter to generate a card view list but cannot find out what exactly is causing this null pointer. The log has it happening when setting the adapter r.setAdapter(rA) in the...

Retrieving Fragment by using Fragment Tag

android,android-fragments,nullpointerexception,fragment
I am getting NullPointerException when retrieving a Fragment by its tag defined during its addition via SupportFragmentManager. Here's the code: FragmentOne fragmentOne = new FragmentOne(); getSupportFragmentManager().beginTransaction().add(R.id.container, fragmentOne,FRAGMENT_ONE_TAG).addToBackStack(null).commit(); FragmentOne fragmentOneInstance = (FragmentOne) getSupportFragmentManager().findFragmentByTag(FRAGMENT_ONE_TAG); Log.i("Fragment One Instance: ", fragmentOneInstance.getTag()); Error report: java.lang.RuntimeException:...

How to pass values from one Fragment to another in a ViewPager?

java,android,fragment
I'm completely new to Android programming. I'm writing an where there are two Fragments: Query and Results. There is a Button and an EditText in the Query Fragment. When the user clicks on the Button, the results from the EditText should be displayed in the TextView that is present the...

How to open List view in a specific place of activity?

android,listview,android-activity,fragment
I want to open the List view from the bottom of screen to almost little high of middle of screen. I have no idea how to do it. I have just idea about it that it could only be done by fragment and I do not know how to use...

How to InfoWindowAdapter and onMArkerClick in Fragment

android,dictionary,fragment
in Activity class i ihave this code: class MyInfoWindowAdapter implements InfoWindowAdapter{ private View view; public MyInfoWindowAdapter(){ view = getLayoutInflater().inflate(R.layout.custom_info_globo_marker,null); } //implemets metod of MyInfoWidowAdapter @Override public View getInfoContents(Marker marker) { TextView tvTitle = ((TextView)view.findViewById(R.id.title)); tvTitle.setText(marker.getTitle()); return view; } @Override public View getInfoWindow(Marker marker) { // TODO Auto-generated method stub return...

Android FragmentViewPager in Fragment

android,android-fragments,android-viewpager,fragment
I'm trying to implement a ViewPager into my fragment. Here is my Code: Parent fragment: @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_parent, container, false); ViewPager viewPager = (ViewPager) view.findViewById(R.id.viewPager); adapter = new CustomPagerAdapter(getChildFragmentManager()); viewPager.setAdapter(adapter); viewPager.setCurrentItem(0); return view; } Childfragment: @Override public View onCreateView(LayoutInflater...

Fragment doesn't show properly in ViewPager

android,android-viewpager,fragment,framelayout
I have an Activity with a traditionnal viewpager component. This viewpager contains MainFragment class (it's a standard fragment). This is the layout of this fragment: <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"> </FrameLayout> Ps: I need to use this framelayout because I can switch with 2 fragments inside according an user...

Back navigation with Fragments / Toolbar

android,fragment,android-toolbar,android-actionbaractivity,fragment-backstack
I'm scratching my head with this one now.... I have an ActionBarActivity that loads an initial Fragment - the original menu is inflated within the activity. Now, I have a navigation bar that, when an item is selected, loads a different fragment and adds this to the backstack. When I...

How to pass Arguments to Fragment from Activity

android,android-fragments,fragment,bundle
I have an activity which instantiates and populates a Fragment through a adopter class. I want to pass values/objects to this Fragment adopter class so that i can dictate layout etc. I have tried passing bundles using the setArgument method but my code bombs out and not sure why. As...

Refresh QuickBadge/ ImageView on a Fragment after taking a picture

android,image,imageview,fragment,android-camera
I want to take a picture in my App, so if I click on my ImageView/QuickBagde on my Fragment. I'm able to take a picture, after that, I crop it and it return to my App. This is not a big deal and it's working well. But how can I...

android.support.v4.app.FragmentPagerAdapter cannot be applied to android.app.FragmentManager

java,android,fragment,android-tabs,fragmentpageradapter
I want to implement just 2 fixed tabs in my application. I followed this tutorial. In my TabPagerAdapter class I'm getting this error : FragmentPageAdapter in android.support.v4.app.FragmentPagerAdapter cannot be applied to android.app.FragmentManager TabPageAdapter class: package com.nikhil.tabs; import android.app.Fragment; import android.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; public class TabsPagerAdapter extends FragmentPagerAdapter { public TabsPagerAdapter(FragmentManager...

OnDrawerItemClickListener Does not work.

java,android,fragment,navigation-drawer
I have been working on this navigation drawer with toolbar.Now am stuck with the click listener. When i click the items in the drawer it does nothing. My class is fragment. Here its the code. package com.vivek.ss; import android.app.FragmentManager; import android.app.FragmentTransaction; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.support.v7.widget.Toolbar; import android.view.Menu; import...

how can I define method in fragment?

android,methods,fragment,zxing
Ihave tried this code while extending Activity and it's run (Y) but when extending fragment as I paste here it give me this exception : java.lang.IllegalStateException: Could not find a method scanQR(View) in the acttyivity class com.example.pc_orbit.myapplication.Citizen for onClick handler on view class android.widget.Button with id 'scanner' public class...

Android Fragment onCreateView after onDestroy not called again

android,fragment,lifecycle,ondestroy
According to the Android fragment lifecycle i would expect that after onDestroy the fragment will be recreated, or at least onCreateView is called again. I have an Activity A starting another Activity B for result and Activity B creating a fragment F. public class A extends FragmentActivity { ... public...

Android set menu items dynamically at startup

java,android,fragment,menuitem,action-menu
I need to change the title of a menu item in my action bar at startup based on a few variables which get created at the startup. But for some reason I cant simply do that since the menu items take time to inflate maybe? how do I get around...

Open an activity with a fragment on it?

android,menu,fragment
I am trying to open an activity with an menu, this works, without any problems. however, when i put an fragment on the activity i open, i get this error 06-19 16:38:46.253 2732-2732/com.example.broodjepoep.stapvoorstap E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.example.broodjepoep.stapvoorstap, PID: 2732 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.broodjepoep.stapvoorstap/com.example.broodjepoep.stapvoorstap.LayoutFragmentOne}: android.view.InflateException: Binary XML...

how to fix NPE from fragment?

android,service,nullpointerexception,fragment
from fragment in my app i need to call public void that state in myService.class. in fact i needed to do actions for buttons of mediaPlayer, that will be called from fragment. when first time press btn_PlayResume - it startService(); when second time pressed - call pause(); and if again...

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...

How to send data from BroadcastReceiver to Fragment in android

android,service,broadcastreceiver,fragment,android-gcm
I am trying to make an chatting app.I have a SlidingDrawer Activity and it has many fragments and among which ChatFragment is one.Now when i am sending message to my friend , i have a Chatting Window and if any message comes from GCM service and i am in ChatFragment...

Working with fragments inside viewpager - android

android,android-fragments,android-viewpager,fragment,android-fragmentactivity
I have problem with position in my viewpager. I have container layout for my fragments that has button. Some fragments have picture, but some of them don't. I want to show button if fragment contains image. I know there is problem with my position that Container sends to fragment, but...

Android: one fragment turning into two fragments on one page

android,fragment
I have an activity that has within it one fragment that takes up the whole screen. At some point in the app flow, the user can go to another screen in the same activity that is composed of two seperate fragments. So you can imagine it as: Fragment A (100%...

how to get the onWindowFocusChanged on Fragment?

android,fragment
I am using Android Sliding Menu using Navigation Drawer. I know that onWindowFocusChanged work on MainActivity. How can I check is it hasFocus on Fragment? someone said that I can pass the hasFocus to fragment, but I dont know how to do this. Can anyone give me some sample code?...

Why does Activity's method onCreateOptionMenu() get called two times by using setHasOptionMenu(true) for it's Fragments?

android,android-activity,fragment,navigation-drawer,oncreateoptionsmenu
I manage some Fragment's in my own ActionBarActivity named MainActivity. One Fragment is shown at one time. The example should be simple. The Fragment which is showing should have got an option menu under certain conditions. Here my code: public class MainActivity extends ActionBarActivity{ ... @Override public boolean onCreateOptionsMenu(Menu menu)...

Cannot instate the type PagerAdapter? What's wrong?

android,android-activity,fragment,fragmentpageradapter
Hey guys I'm trying to swipe between my activities using PagerAdapter but I'm getting error here's my code, I'm a little new to development of Android, so I'm unable to understand the problem where I've found the solution on Internet. Can anybody tell me how to exactly fix it? Any...

Android fragment null pointer exception on rootView [closed]

android,android-fragments,fragment,return-value
Can anybody help me with this I'm using the android navigation fragment template and I'm new-ish to android, I've just started adding some views to the fragment rootView and a TTS engine, but I'm coming up with an error when adding either the onClickListener to a button in my rootView...

IllegalArgumentException: No view found for id in fragments

android,android-fragments,fragment,fragmenttransaction
I tried searching all SO questions but seems its because missing setContentView or need clean the project, my issue its i got java.lang.IllegalArgumentException: No view found for id but its "random" i can't figure out why some devices throw this exception i have Activity->FragmentA->Nested fragment and works great but sometimes...

Going from ListFragment to Fragment using FragmentTransaction - can't go back to the ListFragment

android,listview,fragment,fragmenttransaction
I'll jump straight to the point. I'm making an application with has three tabs (MainFragment, FragmentCategories, FragmentList). What I want to do next is this: From the second tab, FragmentCategories, I open up a certain category. Using getFragmentManager and FragmentTransaction, I open up a FragmentCategoriesList. From there, when I choose...

DialogFragment not recognizing finish() method

java,android,fragment,onclicklistener,android-dialogfragment
Hello ultimately what I am looking to do is to have a DialogFragment show on screen to confirm that the user wants to exit the app. If the user says that they do wish to close the app the app shuts down. If the user does not the DialogFragment goes...

Android Fragments fundamentals: why? Is this conceptually wrong?

android,interface,fragment,communication
I bring you a question about "proper programming" in Android. I am currently developing an app using fragments. It involves dynamically added fragments to Activity, fragments inflated from XML, nested fragments from XML or dynamically added. Let's just say, a bit of everything. The concept this question focus is the...

How to use markerOptions in fragment to get MyLocation using LatLng() Method

android,maps,fragment
I am working on app where i have to show no of Marker on map.I have inflate map through fragment and now want to get my location by using markerOptions().but that show the GoogleMap null. public class MapFineTech extends Fragment { GoogleMap googleMap; double getlatitude,getlongitude; String latitude_mString,longitude_mString; MapView mapView; ViewGroup...

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...

ListFragment With Custom ArrayAdapter Scroll issue

c#,android,xamarin,fragment,adaptor
Hi I am new to Android/Xamarin Dev and i have a problem. I follow a example from here . I have a ListFragment with Custom ArrayAdapter . I make it Like this (ViewHolder) and when i scroll down my items get confused . What i mean is If i have...

android fragment cannot open in the emulator

android,fragment
Firstly I'm new android and English :) sorry about that. I've a problem with Fragment manager. I read some code for using fragment in the main activity. However it's cannot run in emulator and also you can see the codes in below. I think the problem that about "import android.support.v4.app.FragmentManager;"...

Fragment activity not opening via `Intent`

android,google-maps,android-fragments,dictionary,fragment
I'm trying to add Markers on Map' by usingLatLangvaluesListView. I used 'setOnItemClickListener() to launch next activity which contain Fragment for map. But when i click any of the ListView item the App closes. My Code is InboxActivity.java public class InboxActivity extends ActionBarActivity { String phoneNo; @Override protected void onCreate(Bundle savedInstanceState)...

Android Fragment Simple Button [closed]

java,android,android-fragments,crash,fragment
Why is my application crashing on start up? I am trying to control layout elements from the Placeholder fragment. import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBar; import android.support.v4.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.os.Build; import android.widget.Button; import android.widget.TextView; public class MainActivity extends...

Button inside fragment

android,button,fragment
I'm hoping someone can help me with this extremely annoying problem. I'm new to working with fragments. I've have spend two days trying to get buttons to work inside my fragment. My app is a tab activity with sliding fragments auto created by android studio. I can change fragments by...

how to convert activity to fragment

android,android-activity,android-fragments,fragment
I am trying to use navigation drawer, I have an Activity code which contains a ListView. I want to convert all the Activity to Fragment, how can I do this? Please can someone post my code converted into Fragment ? This is my activity code: public class SceltaDiete extends ActionBarActivity{...

Activity cannot run due to the null pointer exception

android,android-fragments,android-activity,nullpointerexception,fragment
I created the code below import java.util.ArrayList; import android.app.Activity; import android.app.Fragment; import android.app.FragmentManager; import android.content.res.Configuration; import android.content.res.TypedArray; import android.os.Bundle; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v4.widget.DrawerLayout; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ListView; public...

TabHost displays content once (onCreate)

java,android,fragment,navigation-drawer,android-tabhost
I have a TabHost Inside a navigationDrawer and I'm facing this weird problem which occurs when ever i go from TabHost which exist as a navigation drawer item to another navigation drawer item and get back to TabHost it won't display its content, the first time it works perfectly but...

Android how to send data to a running fragment

android,android-fragments,fragment
is there a way to send some data from an activity to a running fragment? In my app I'm adding a second fragment over another fragment. I intentionally use the add method instead of the replace method. So now I want to hide my second fragment with fragmentManager.popBackStack(); and my...

SAPUI5 My fragment gets closed

fragment,sapui5
I'm Developing SAPui5 APP. I create a fragment xml with a sap.m.Popover, In Content of Popover I add 2 sap.m.MultiCombobox. When I close the selection of multicombobox my popover gets closed. Any solution? Fragment code: <core:FragmentDefinition xmlns="sap.m" xmlns:l="sap.ui.layout" xmlns:core="sap.ui.core"> <Popover class="sapUiPopupWithPadding" title="Filtro Asignación" placement="Top" > <l:VerticalLayout> <Label text="Fecha" ></Label> <DatePicker...

How to replace fragment in BaseAdapter?

android,android-fragments,fragment
My Adapter : public class MyAdapter extends BaseAdapter { ... public View getView(int position, View convertView, ViewGroup parent) { View view = mLayoutInflater.inflate(R.layout.my_listview_item, null); TextView myTv = (TextView) view.findViewById(R.id.myTv); myTv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // I want to replace another fragment } }); return view; }...

Android ViewPager center item on screen

android,dialog,android-viewpager,fragment,center
I am trying to show a dialog over my screen. And that dialog should have ViewPager in it with FragmentPagerAdapter. Each item in adapter has width set to .7f. What is important to me is that when some item is selected it should be snapped to center of the ViewPager...

how change fragment textview with own java class?

java,android,android-fragments,android-activity,fragment
I tried to change a TextView in Activity of Fragment in three cases, but I can't change the TextView. Is there any solution to change a TextView of Fragment in own Fragment_Activity or Main_Activity? Fragment.java @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { mParam1 = getArguments().getString(ARG_PARAM1);...

Android Custom Adapter - Won't return view?

android,listview,fragment,baseadapter,custom-adapter
I'm having a problem with returning my view to a listview with my custom adapter. This is what I have in my main class which extends Fragment. public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_perfil_config, container, false); ListAdapter adapter = new PerfilOptionsAdapter(listOptions(), getActivity()); listPerfilConfigOptions =...

How to use method onNewIntent(Intent intent) inside a Fragment?

android,android-activity,fragment,nfc
I'm trying to use NFC Hardware from my device. But, the problem is that when I register the Activity to receive the Intent: PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); I receive the result in an Activity instead of a Fragment. Is there a way to handle this...

Android toolbar inside a tab menu retrieval

java,android,menu,fragment,toolbar
How do I get a menu for my toolbar inside a fragment (tab)? I'm relatively new to android and java. Here's the code: import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v7.app.ActionBarActivity; import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class Tab1 extends Fragment { @Override public View onCreateView(LayoutInflater inflater,...

Why are onPrepareOptionsMenu(Menu menu) and onOptionsItemSelected(MenuItem item) not displaying any menu?

android,menu,fragment,menuitem
I have a problem regarding to the menu which is not showing up when I tap on the menu option. Since I have used onPrepareOptionsMenu(), I was expecting that I have dynamically modified the menu content but it didn't show any menu even after I applied the method onOptionsItemSelected(). *The...

Android how toggle with the button in toolbar to open/close navigation drawer with Fragments

java,android,fragment,navigation-drawer,toolbar
I am new in Android Development after reading so many tutorials and documentation and spending some time finally i managed to create a navigation drawer with the toolbar. but currently the problem is i can only open drawer by swiping from left side of the screen (not capable open/close drawer...

CircularFloatingActionMenu in Fragment of ViewPager

android,android-fragments,android-activity,android-viewpager,fragment
In my android application I have ViewPager with some Fragments. I wanted to use and show Circular Floating Action Button Menu in one of this Fragments but FAB somehow visiable in all Fragments. How to solve this problem and show FAB only in one Fragment. By the way it is...

Android - show fragment with custom text in view

java,android,android-fragments,fragment
I need to show several fragments on the screen. All fragments are instances of one fragment class, but I need to be able to set my values to view attrbutes on these fragments (text in TextView for example). I tried many solutions from here, but didn't find one. What I'm...

Serializing execution of multiple fragments using AsyncTask

android,android-activity,android-asynctask,fragment
I'm having an activity with 2 fragments, called A and B. Fragment A has an AsyncTask to parse some data from the internet into an array of custom objects and fill its interface. Fragment B also has to use this array to update its interface. The question is, how can...

Android Studio - getChildFragmentManager / android-support-v4

fragment,android-tabhost,navigation-drawer,android-support-library
I cannot solve the problem with android-support-v4. All "Extras" including "Android Support Repository (11)" and "Android Support Library (21.0.3)" - Installed. I was trying a lot of ideas which I found, but nothing help. I am AndroidStudio beginner. Here is my builg.gradle: apply plugin: 'com.android.application' android { compileSdkVersion 21 buildToolsVersion...

Null error in Activity trying to access SQLite table

java,android,sqlite,fragment
Newbie question time again; So within FormActivity I post then receive a response from a SQL table on a remote server, the data is put into a local SQLite table row. Then, I have a Fragment with several EditText fields which I try to populate with the local table data....

Save Spinner with SharedPreferences in fragment (OnItemSelectedListener)

android,fragment,sharedpreferences,spinner,onitemselectedlistener
I am new to Android programming and at the moment I am trying to make some spinners with four array elements (string-array), and then save the current state with shared preferences. I've already done a lot of research, but most of the solutions only work for activities, and I am...

To pass the values of json array in listview

android,json,listview,fragment
i'm working on a student record project And there are four fields in it like class name roll no. marks and User is putting data into it by edit text and i'm storing the values into the json Array . Also i'm putting values in array list and i'm passing...

notifyDataSetChanged not refreshing listview fragment

android,listview,fragment,notifydatasetchanged
I have searched as much as I could on google, I have search as much as I can find on here, I am seriously at a loss, my co-workers are unhelpful, i just want someone to look at this and tell me what it is I am missing that is...

I want my button to call a method in a fragment

android,button,fragment
So I have (WorkoutList Activity) -> (WorkoutList Fragment) -> (ExerciseList Fragment) -> (addExercise Fragment) Theres a button in AddExercise, and I want it to invoke a method in ExerciseList The problem is that with the current set-up I'm getting `Attempt to invoke virtual method void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object...

Caused by: java.lang.IllegalArgumentException multiple fragments

android,fragment,illegalargumentexception
I speend a lot of time at this issue, I don't know where is problem. I have got Activity with Fragment A. Fragment A have got second Fragment B and B have got Fragment C. Activity: layout -> with R.id.container (place where put next fragment) A: layout -> with R.id.place_promo...

Viewpager onClickListener reference the wrong view in android

android,events,imageview,android-viewpager,fragment
First of all the viewpage preload the next page and previous page. So if I currently view the PageB , it actually store the Page A and Page C view as well. And it caused the problem. When I am in pageB, I press a onClickListener on it, it get...

Restoring instance variables in Android upon activity recreation

android,android-activity,tabs,fragment,recreate
I have an Android project for which I am creating a custom tab view. I have structured the main Activity (FragmentActivity) in such a way that it has a tab bar at the bottom of the screen with a FrameLayout above it. Each option on the tab creates a new...

KeyEvent.KEYCODE_BACK getting called twice in Fragment

android,fragment
I am calling KeyEvent.KEYCODE_BACK on my View in my fragment and for some odd reason it gets called twice. I have no idea as to why it is behaving this way. Here is my fragment: @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { myFragmentView = inflater.inflate(R.layout.folders, container, false);...

Replacing layout with another in Android

android,fragment
I have an app where user can change the content of the layout by pressing a button but when i want to replace a layout i get error in replacement line: This is addtotry.xml code: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <RelativeLayout android:orientation="horizontal" android:layout_width="150px" android:layout_height="fill_parent"...

Open child fragment from NavigationDrawer Section

android,fragment,navigation-drawer
i'm trying to open child fragment from an fragment of Navigation Drawer. Look at the picture below for understand me better please. CODE: FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); fragmentTransaction.replace(R.id.fragment_container, new ChatFragment(), MainActivity.CHAT_FRAGMENT_TAG); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); ERROR DEBUG: java.lang.IllegalArgumentException: No view found...

Cannot resolve symbol 'fragment'

android,android-layout,fragment
compile 'br.com.liveo:navigationdrawer-material:1.0.5' compile 'com.android.support:support-v4:22.0.0' compile 'com.android.support:support-v13:22.0.0' compile 'com.android.support:gridlayout-v7:22.0.0 When I add the above fragment to my project and run the Android gradle build task for the project, the fragment is not imported or built What am I doing wrong?...

How to tweak MapFragment (Android)

java,android,dictionary,fragment,marker
I have made a MapFragment which basically is GoogleMaps. This Fragment is called in an activity, through the fragmentManager and fragment transaction. I would like to tweak my Map now to add some markers and dynamic zoom aswell. I am a bit struggling with this at the moment. Maybe some...

Updating the contents on tab changed in view pager

android,tabs,android-viewpager,fragment,pagerslidingtabstrip
I am scracthing my head for past 1 day but unable to find the solution. In mine application there are two tabs under the toolbar First tab is USER-TAB the second one is ADMIN-TAB In both the tabs there are the listView. When a ListItem on the USER-TAB is clicked...