android-fragmentactivity

How to communicate between fragments?

风流意气都作罢 提交于 2019-12-17 14:57:08
问题 I am developing an Android application. I have a requirement like there is a button in fragment 1, when a user clicks that button result should be displayed in fragment 2. While loading the activity both fragments is attached. Here is my try: In main activity: public void dsp(String str) { secondfragment f2=new secondfragment(); Bundle bundle = new Bundle(); bundle.putString("edttext", "From Activity"); f2.setArguments(bundle); } In first fragment: public View onCreateView(LayoutInflater

Pass data between two fragments without using activity

主宰稳场 提交于 2019-12-17 12:08:40
问题 I want to pass data between two fragments without using activity and fragment activity. I don't want to pass data between fragments using activity like this : Communicating with Other Fragments Below is my scenario : I have one Parent fragment and inside that there are two child fragments.Now my need is to pass data between these two fragments.How to achieve this? I looked into this : Event Bus but not getting working example for fragments. Is there any other alternative to pass data between

Start an activity from a fragment

落爺英雄遲暮 提交于 2019-12-17 04:44:29
问题 I have 2 fragments with on both fragments a button. When I press the button I'd like to start a new Activity. But I can't get it to work. The error I'm getting: ERROR here: Type mismatch: cannot convert from mFragmentFavorite to Fragment What am I doing wrong? MyFragmentPagerAdapter import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; public class MyFragmentPagerAdapter extends FragmentPagerAdapter{ final

How can I access getSupportFragmentManager() in a fragment?

人盡茶涼 提交于 2019-12-17 03:52:05
问题 I have a FragmentActivity and I want to use a map fragment within it. I'm having a problem getting the support fragment manager to access it. if (googleMap == null) { googleMap = ((SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map1)).getMap(); // check if map is created successfully or not if (googleMap == null) { Toast.makeText(getApplicationContext(), "Sorry! unable to create maps", Toast.LENGTH_SHORT) .show(); } } // create marker MarkerOptions marker = new

Android strange behavior on orientation change with Custom View in fragment

喜夏-厌秋 提交于 2019-12-14 03:48:39
问题 I have a FragmentActivity which shows a Fragment by defualt. The fragment consists of an EditText , a TextView and a Custom DropDown, made by extending AutoCompleteTextView . If my custom AutoCompleteTextView is focused or the drop down list is open and I change the orientation of the device. I get following exception: Failed Looking up window java.lang.IllegalArgumentException: Requested window null does not exist It works if the custom AutoCompleteTextView is not in focused state. I've

error OnListItemClick and setListAdapter is undefined for the type fragment

夙愿已清 提交于 2019-12-14 03:15:10
问题 i have error in onListItemClick error message is "The method onListItemClick(ListView, View, int, long) is undefined for the type Fragment" and setListAdapter error message is "The method setListAdapter(SimpleCursorAdapter) is undefined for the type ReviewFragment", this my full code, import android.app.Fragment; import android.os.Bundle; import android.support.v4.widget.SimpleCursorAdapter; import android.app.AlertDialog; import android.app.ListActivity; import android.content

Null Pointer exception passing data from activity to Fragment

亡梦爱人 提交于 2019-12-13 22:11:49
问题 I have the url value in the MainActivity page and i need to pass this url value from ACtivity to Fragment. But when i click the button i'm getting null exception on the line of String url=getArguments().getString("btn_url"); Activity: Fragment fragment=new About(); if (fragment != null) { FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.frame_container, fragment, "TAG_FRAGMENT"); transaction.addToBackStack(null); transaction.commit(); Bundle

How to show GoogleMap inside ConstraintLayout?

做~自己de王妃 提交于 2019-12-13 15:26:29
问题 I created a new project "MapsActivity". I got my API key from Google, placed the API key in google_maps_API.xml(debug) inside the YOUR_KEY_HERE area. I see in AndroidManifest it's there. Then I go to build/run the app and it crashes. I didn't even code anything yet. According to Android Monitor here's the crash report: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.maps.SupportMapFragment.getMapAsync(com.google.android.gms.maps

How is my fragment's onCreateView called before it's onCreate when finishing the activity in onCreate?

∥☆過路亽.° 提交于 2019-12-13 14:22:34
问题 This is very odd. I have a simple app which once logged in shows a fragment in an activity. The app also has an inactivity "timeout" after which time it finishes the activity and shows the login screen -- if the app is in the background when the timeout occurs then when the next onCreate or onStart event occurs in the activity it is finished. However sometimes when returning to the logged in activity I get a NPE in the onActivityCreated method of my fragment. The fragment is very simple and

Enable an ActionBar Button each time navigation within tabs occurs.

ε祈祈猫儿з 提交于 2019-12-13 13:47:12
问题 I have a main activity in which I designate tabs using three fragments. I have a button on the ActionBar which navigates to a different fragment say "Info about the app" Once user navigates to this particular fragment (Info) I disable it so that it is not called again and again. Then on the back key in the main activity I re-enable it. So far so good. But I am not able to re-enable it for one scenario: Say if user navigates to the info fragment and does not press back, but however if he