FAQ Database Discussion Community


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

Adding actionbar to FragmentActivity

android,android-fragments,android-actionbar,android-fragmentactivity
I am making an app that is using google maps for some specific reason. So I created an Google Maps app in Android Studio and I got an activity that extends FragmentActivity. Everything works perfectly but now I want to add the action bar at top of the screen. The...

What is a good ratio of Activity : Fragment?

android,android-activity,android-fragments,android-fragmentactivity
I have a simple App with a few views. Theres the main view which is first loaded and displays the information, then from there I call the other view depending on what they click. Would it be wise to have one activity calling all the other fragments? Or should I...

my two fragments under the same activity are shown one above the other

android,android-layout,android-fragments,android-fragmentactivity
I have an activity: public class MainActivity_with_Fragment extends RoboFragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_activity2); if (savedInstanceState == null) { getSupportFragmentManager().beginTransaction() .add(R.id.container, new SettingsFragment()) .add(R.id.container, new AddReminderFragment()) //.add(R.id.container, new ReadRemindersFragment()) .commit(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { //...

Android use FragmentActivity instead of TabActivity

android,android-fragments,android-activity,android-tabhost,android-fragmentactivity
I want to change TabActivity to FragmentActivity because TabActivity is deprecated. My code is public class Fragment_Activity extends TabActivity implements TabHost.OnTabChangeListener { /** Called when the activity is first created. */ TabHost tabHost; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_tabs); // Get TabHost Refference tabHost = getTabHost(); // Set...

Using ViewPager and PagerTabStrip - extending FragmentActivity

android,android-fragments,android-viewpager,navigation-drawer,android-fragmentactivity
First - sorry for the newbish question. I've started building an app that has a single Activity and a navigation drawer. Each menu item loads a new fragment in the middle frame layout. I want to create another fragment that: has tabs allows for swipe scrolling It seems like the...

PopBackStack but keep the first fragment in android

android,android-fragments,android-fragmentactivity,back-stack,fragment-backstack
I am working on fragment transaction, and the backstack is like this: fragA => fragB => fragC => fragD I would like to return to fragA after back fromn the fragD fragD => onBackPress => fragA So, I tried code like: getChildFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); but it clear all the backstack ,...

How can I use set fragment inside my class which extends the Fragment class?

android,android-fragments,android-fragmentactivity
Null returned from ((MessageTextFragment)fragment).setActionButtonStateListener(bAction); Here is the SetupMessageFragment.java package com.mayday.md.fragment; import com.mayday.md.MainActivity; import com.mayday.md.R; import com.mayday.md.WizardActivity; import com.mayday.md.adapter.PageItemAdapter; import com.mayday.md.common.AppConstants; import com.mayday.md.common.AppUtil; import com.mayday.md.common.ApplicationSettings; import com.mayday.md.common.MyTagHandler; import com.mayday.md.data.PBDatabase; import...

Error in Google Map API inside Navigation Bar Fragments

android,google-maps,android-fragments,android-fragmentactivity,google-api-client
I am trying to build an app with Navigation bar and Google Map API in it. I followed both of these: http://www.androidhive.info/2015/04/android-getting-started-with-material-design/ http://blog.teamtreehouse.com/beginners-guide-location-android tutorial and when I put the map tutorial into one of the fragment inside the navigation bar I'm getting these error: myGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this)...

Fragment not showing

android,android-fragments,navigation-drawer,android-fragmentactivity,android-navigation
So I've been basing my navigation drawer after code i found in a tutorial. However my fragments don't switch. Laptop is down and using AIDE. Anyone tell me what's wrong? Guessing it's my setonitemclicklistener. { private ListView mDrawerList; private DrawerLayout mDrawerLayout; private ArrayAdapter<String> mAdapter; private ActionBarDrawerToggle mDrawerToggle; private String mActivityTitle;...

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

Refresh fragment inside viewpager

android,android-fragments,android-viewpager,android-fragmentactivity,viewpagerindicator
In my example am having a view pager inside a fragment and tabs in View pager are crated dynamically. For example, am having tab for three subjects Sub 1, Sub 2, Sub 3 each subject tab having some number of questions. Now what i want is when i switch from...

Up Navigation in fragment

android-fragments,navigation-drawer,android-fragmentactivity,up-navigation
hi i am creating one android app in which i want to implement up navigation. i want to navigate to previous fragment through up navigation in actionbar. application also contain navigation drawer. i have implement following code but it does'n work. thanks in advance. main activity code as below. public...

List fragment not disappearing

java,android,android-intent,android-fragments,android-fragmentactivity
Based on my code whenever I run my app and click a list item, the intended fragment does appear but the list fragment does not disappear from view (see attached screenshot). What needs to be done in order to remove the list from the user's view? FragmentItem1 newFragment = new...

Change fragment on click

android,android-fragments,swipe,android-fragmentactivity
I have to implement an application in which the user can click through a bottom_bar between 5 pages (although google does not recommend it in recent documents, the customer is always right). So I created a swipe activity with automatic tool android study. Question: how do I start the transation,...

Cannot resolve finish() in intent in Fragment in Android Studio

android,android-fragments,android-fragmentactivity
Intent myIntent = new Intent(viewEnterChildExp.getContext(), MainActivityExpenses.class); myIntent.putExtra("fromEnterChildExpenseToMainActivityExpenses", "true"); startActivity(myIntent); finish(); I'm using the above code snippet in fragment The finish() is in red color. When I put mouse cursor over it, an error is popped: can resolve method finish() TIA!...

Why can't I update my view fragment phoneNumberEditText?

android,android-intent,android-activity,android-fragments,android-fragmentactivity
I am returning the phone number as a string. I verified it in my logcat. I am trying to use the phoneNumberEditText.setText(phone); to set the phone number which was defined in the class's scope private EditText phoneNumberEditText; I also tried casting the phone as CharSequence I keep getting this error...

How to pass data from fragment activity to fragments

android,android-intent,android-fragments,android-fragmentactivity
I am doing service call in FragmentActivity where I need to pass two datas(name and address) to Fragment A and Fragment B respectively. Here is my code which I tried. public class C extends FragmentActivity { // public PassDataToFragments fragmentCommunicator; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.detail_pager); serviceCall();...

Fragment Transaction not working when using AppCompatActivity or FragmentActivity

android,android-fragments,android-fragmentactivity,appcompat,back-stack
I have a typical application. An activity which has a FrameLayout and in this layout I want to switch between fragments. This is typically and easily done with: getFragmentManager().beginTransaction() .replace(R.id.ac_container, new FrOverview()) .addToBackStack(null) .commit(); The problem is, that even if I use .addToBackStack(null) (And I know it's been added 'cause...

How to Add FragmentActivity to FrameLayout

android,android-fragments,android-fragmentactivity
scenario: I have the mainActivity in which it holds the default game list fragment When user clicks an item on the list it should show the FragmentActivity that contains a viewpager with two tabs inside the framelayout basically replacing the default game list fragment. question: how can I add FragmentActivity...

How do I create a pop-up Android Fragment that takes in a text input before returning to my main activity?

android,android-fragments,android-fragmentactivity,android-dialogfragment
For my app, I want my user to be able to press a "Change User" button, have a fragment pop-up, take in a text input, and then save to shared preferences upon exit, returning to the activity it was called from. I would like my methodology to be similar to...

Android fragments refresh every time after returning back to them

android,android-fragments,android-fragmentactivity
This has to be really simple but I've never worked with fragments before and I'm lost here. I searched and found tons of stuff on fragmets but I can't find an answer to my problem. On my main activity I have a submenu with 5 buttons, basically a LinearLayout. I...

How to get context of another activity which is not started yet ?

android,android-intent,android-activity,android-fragmentactivity
I want to use context of activity 'A' for start activity 'B' from activity 'C' where activity 'A' is never started yet. I am using the below line but it is not working. public static ContextActivityA aContext = new ContextActivityA(); so is there any way to get context of another...

Null object reference in list view

json,android-fragments,android-listview,android-fragmentactivity
I have a listview in a fragment that I am populating with information from a JSON call. I am having an issue wetting up the listview in my fragment. My fragment only extends Fragment and I am assuming this may be where my issue is. the sample code I was...

Back to a fragment from fragmentActivity in Android

android,android-intent,android-fragments,android-fragmentactivity
I'm trying to get back to a fragment from a fragmentActivity, but it is not working, I'm getting NullPointerException, When I hit cancel I need to update the previous fragment. How can I get back to a fragment and update it? don't know why this is happening. public class AddEscolas...

How to pass parameter to Fragment from FragmentActivity

java,android,android-fragments,android-fragmentactivity
I have a FragmentActivity in my android application. I use a viewPager to insert tabs in the activity. So I have this code. It works. public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.view_clienti); Bundle extras = getIntent().getExtras(); if (extras != null) { String datas= extras.getString("Cliente"); if (datas!= null) { System.out.println("pippo"); }...

Action bar menu is not shown in Fragment Activity

android,android-actionbar,android-fragmentactivity
I'm trying to display my actionbar menu within my Fragment Activity The problem is, if I select (in android studio) the Material theme, there is no problem to see the action bar menu, but when I test my app on my own phone (Samsung S5), the menu is not shown....

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

Back to Home Fragment when I press on back button

android,android-fragments,android-fragmentactivity
My MainActivity contains 4 fragments. My home-fragment is FragmentA. When I press on back button at FragmentB,C or D, I have to return back to FragmentA. If I am on FragmentA and press back button, I have to moveTasktoBack(). What is the best way to do it?...

Re-create fragment properly

android,android-fragments,android-fragmentactivity
I want to re-create Fragment. After I did something like fragmentTransaction.detach(someFragment); fragmentTransaction.attach(someFragment); fragmentTransaction.commit(); onAttach is not being called but only onCreateView, which means that fragment was not-really re-attached. Please advise how to make full detach/attach cycle. Thank you!...

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

getSupportFragmentManager is not recognized

android,android-fragments,android-fragmentactivity
As shown below in the code, the MainActivity extends FragmentActivity, and TabsPagerAdapter extends FragmentPagerAdapter. I do not know why eclipse does not recognize this line viewPager = new TabsPagerAdapter(getSupportFragmentManager(), this.fragList); MainActivity: import java.util.List; import com.example.settingsviewpagertabs.adapter.TabsPagerAdapter; import android.app.ActionBar; import android.app.ActionBar.Tab; import android.app.Activity; import android.app.Fragment; import android.app.FragmentTransaction; import android.os.Bundle;...

How to change activity of a screen with swipe? with some example

android,android-activity,android-studio,android-fragmentactivity,swipe-gesture
I have 2 screens black with scroll View in it and then I would like to change these screen with a swipe. I am using Android Studio and want to have a simple example so that i could change all the screens from one to other using swipe view. I...

Information not passing from doInbackground to postexecute using inappbilling

android,android-asynctask,in-app-billing,android-fragmentactivity
I start an AsyncTask when my apps start so that user premium features will be show right away. But i am not getting info passed from doInBackground (the values after the query) to onPostExecute. I do a queryInventoryAsync that defines values are true or false then I use this values...

I want to transfer data from activity to fragment and then display data in the fragment. My code doesn't work

java,android,android-fragments,android-fragmentactivity
Activity class is MainActivity.java, Fragment class is frganswer.java. I am taking two numbers in the activity using edittext and then I need to display its sum in the fragment. There are no errors, but when I try to run it on the AVD, it goes 'not responding'. Please point out...

Fragment or Activity?

android,android-activity,fragment,android-fragmentactivity
Hi all android noob here. One of the difficulties I have in android is choosing what to load should I load the fragment or should I fire an activity? My module will from a recyclerview, once user clicks on the item it will take them to another screen which contains...

ActionBar Badge returns optionitemselected click to Activity instead of my Fragment

android,android-activity,android-fragments,android-fragmentactivity,android-actionbar-compat
I have onOptionsItemSelected(MenuItem item) in my fragment. Now I'm forced to use Android-ActionItemBadge library(https://github.com/mikepenz/Android-ActionItemBadge), to add the ActionBar Notification Count. so I added the piece of code in my Fragment. public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { //Inflating the Menu inflater.inflate(R.menu.refresh_menu, menu); //inflating Notification Icon if (badgeCount > 0) {...

Content Provider ListView Limit

java,android,android-listview,android-fragmentactivity
I would like to limit the amount of contacts displayed in my app. Currently it is querying my Contactscontract.Contacts DB and returning every primary display name that has a phone number. Is there a simple way to reduce this to a numerical amount (say only display 5 contacts), or to...

how to fetch data from php and display in android listview in FRAGMENT?

android,json,listview,android-fragments,android-fragmentactivity
Error throwing in onPostExecute(): The constructor SimpleAdapter(Commodities, ArrayList>, int, String[], int[]) is undefined The problem is in onPostExecute() of my AsyncTask: @Override protected void onPostExecute(Void result) { super.onPostExecute(result); ListAdapter adapter = new SimpleAdapter(Commodities.this, matchFixtureList, R.layout.list_item, new String[] { TAG_SCRIPT, TAG_BUYSELL, TAG_TRADESELL, TAG_TARGET, TAG_STOPLOSS, TAG_STATUS }, new int[] { R.id.Script, R.id.BuySell,...

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

Caldroid Dialog and FragmentActivity

android,android-fragmentactivity,caldroid
I'm building an app in which I need a calendar so the user can pick a date. I'm trying to embed the Caldroid library in my project and I want to show the calendar not in a new Activity, but in a Dialog instead. My questions are: Since I'm using...

How to cast the cursor from a fragment to a new activity?

android,android-fragments,android-fragmentactivity,android-cursoradapter,android-cursor
I have a working ListView, in a fragment and when the ListItem is clicked I want to link the data to a new Activity. I am getting an error that my db object cannot be cast to the db Cursor import android.app.ActionBar; import android.app.FragmentTransaction; import android.content.Intent; import android.database.Cursor; import android.os.Bundle;...