fragment

Caused by: java.lang.IllegalStateException: Fragment already added

限于喜欢 提交于 2019-12-22 08:03:03
问题 My MainActivity's onStart() throws IllegalStateException with 'Fragment Already Added' message. What am i doing wrong? public class MainActivity extends FragmentActivity implements ServiceConnection { @Override protected void onStart() { super.onStart(); } } Following is exception stacktrace: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx/com.xxx.MainActivity}: java.lang.IllegalStateException: Fragment already added: cj{38f8de4c #0 id=0x7f0b0079 cj} at android.app

Android Fragment Basics Tutorial

寵の児 提交于 2019-12-22 07:05:30
问题 So I've been stuck on the third tutorial on the Android Developer Site about Fragments for few days. I just can't understand how the app populates data when I run the app on a tablet (big screen layout). I can understand how the data is being populated on a smaller screen (phone screen). How does the bigger screen list populate with data? Here is a link of the whole project from Android.com tutorials. MainActivity Class public class MainActivity extends FragmentActivity implements

Call method from Kotlin class

a 夏天 提交于 2019-12-22 05:34:11
问题 I have an util Kotlin class where I set toolbar title, hide or show toolbar depends on the fragment: class MyToolbarUtils() { fun hideToolbar(activity: Activity) { (activity as MainActivity).supportActionBar!!.hide() } fun showToolbar(activity: Activity, tag: String) { setToolbarTitle(tag, activity) (activity as MainActivity).supportActionBar!!.show() } fun setToolbarTitle(tag: String, activity: Activity) { var title = "" when (tag) { "Main_fragment" -> title = activity.resources.getString(R

Back navigation with Fragments / Toolbar

家住魔仙堡 提交于 2019-12-22 05:25:11
问题 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 do this, there are a couple of things I want to set: Set the home as up indicator Invalidate the options menu from the main activity Set has options to true for the Fragment Ensure that the up indicator correctly

The fragment which is got from backstack, call onCreateView() again

∥☆過路亽.° 提交于 2019-12-22 04:45:10
问题 Please help me resolve my issue. I have MainActivity with a framelayout. I want to replace some fragments into the framelayout. Now I am encounering an issues, it's: 1) I created and put fragment A to framelayout. Fragment A called onCreateView ...etc. 2) Then I created and put fragment B to layout... Fragment A was put on backstack and it called onPause() (not called onDeattach() , onDestroy ...) 3) I pressed back button. Fragment A was got from backstack, but it called onCreateView() again.

One fragment for multiple activities

青春壹個敷衍的年華 提交于 2019-12-22 04:36:25
问题 We always have heard using multiple fragments with one activity. Is opposite possible? I am curious about this. Can we use same fragment for multiple activities. Please give ONE EXAMPLE. 回答1: How to reuse one Fragment in multiple Activities The green background with two buttons is a single fragment that is reused among multiple activities. 1. Make your fragment class and layout MyFragment.java import android.support.v4.app.Fragment; public class MyFragment extends Fragment implements View

Android getActivity() always returns null inside fragment

三世轮回 提交于 2019-12-22 04:24:07
问题 I have a strange problem in which I encountered:The getActivity() method always returns null inside fragment. I calling it after the onAttach() and onCreateView() are finishing their run. This fragment lives inside a FragmentActivity() that contains stack of fragments, and the way I adding fragment to it is: (This code is being called from the onCreate() of the Fragment Activity()) SmartFragment fragment; fragment = (SmartFragment) Fragment.instantiate(this, fragmentClassName, params);

Android: Changing visibility on menu items with changing fragment

雨燕双飞 提交于 2019-12-22 04:07:57
问题 I want to change the visibility of menu items of a fragment activity (abs) when ever I change the fragment in the activity. The fragments are SherlockListFragments. The menu items I want to show/hide are spinners I create on menu creation: public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. MenuInflater inflater = getSupportMenuInflater(); IcsSpinner herbSortSpinner = new IcsSpinner(this, null, R.attr.actionDropDownStyle);

how to hide the divider between preferences in fragment

人盡茶涼 提交于 2019-12-22 03:41:23
问题 I want to hide the divider between preferences in fragment. The code is below: 1.SettingsActivity.java public class SettingsActivity extends PreferenceActivity { super.onCreate(savedInstanceState); SettingsFragment settingsFragement = new SettingsFragment(); FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.add(android.R.id.content, settingsFragement, "settings"); transaction.commitAllowingStateLoss(); } 2.SettingsFragment.java public class

Custom Date Time picker using NumberPicker and FragmentDialog in android

爱⌒轻易说出口 提交于 2019-12-22 01:39:24
问题 I want to a custom Date Time Picker Dialog exactly as shown in the image. In my project this is dialog is shown when clicked on a TextView which is in a Fragment . I know that I need to use NumberPickers which populates the dates From Current date till all the dates next week. The default android date and time pickers doesnt fit my required so I need to create my own custom `DateTimePicker fragmentDialog'. My required DateTimePicker <LinearLayout android:background="@color/background_default