android-fragments

Android app crash after setText on a TextView

丶灬走出姿态 提交于 2021-01-29 09:12:16
问题 I'm trying to set the text of a TextView programmatically. In my app I'm calling a method which creates a TableRow with a View inside. This View contains a TextView . And now I'm trying to change the Text with the method setText() . city_layout.xml ... <TextView android:id="@+id/textView_City_Name" android:layout_width="match_parent" android:layout_height="match_parent" android:text="@string/city_name" android:textColor="#FFFFFF" android:textSize="35dp" android:gravity="center_horizontal"

How to pass data from Activity to Fragment using bundle

被刻印的时光 ゝ 提交于 2021-01-29 08:46:39
问题 I am completely new to Android and I have to submit this app to end my college degree, but I am having this problem where my fragment crashes my entire app. To explain what I have done up until now is, I have a LoginActivity where I sent the userId through the Intent and have the id of the current user on my DashboardActivity (and I can display it), but in the DashboardActivity I have a bottom navigation bar that navigates to my FormFragment and my DataFragment. Right now, want I would love

How to implement facebook banner ads in fragment?

﹥>﹥吖頭↗ 提交于 2021-01-29 08:37:40
问题 I am beginner i need to show facebook banner ads in fragment can any one guide how to implement banner ads facebook activity code into fragment? public class YourApplication extends Application { @Override public void onCreate() { super.onCreate(); AudienceNetworkAds.initialize(this); adView = new AdView(this, "IMG_16_9_APP_INSTALL#YOUR_PLACEMENT_ID", AdSize.BANNER_HEIGHT_50); LinearLayout adContainer = (LinearLayout) findViewById(R.id.banner_container); adContainer.addView(adView); adView

Why are my CheckBoxe's state never saved?

大城市里の小女人 提交于 2021-01-29 07:39:41
问题 I have a few CheckBox elements inside one of my Fragments . Every time I leave this Fragment it seems to nor save or restore the checked state of each one provided by the user. In the FragmentList example you can find: CheckBox check1; boolean active; @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putBoolean("state1", check1.isChecked()); } Which you can use later like this: @Override public void onActivityCreated(Bundle

How to re-position the grid layout elements in fragments on orientation change?

五迷三道 提交于 2021-01-29 07:11:00
问题 I am having a bottom tabbed activity with three fragments Home, Dashboard and Notifications. In the first fragment, I am having 4 layouts with a button in each layout. These 4 layouts are aligned ina grid view having positions as column:rows (1:1 1:2 2:1 2:2) while in portrait orientation. But how to auto-arrange these layouts when in landscape mode i.e. either as (1:1 1:2 1:3 1:4) based on the horizontal area available during landscape? Xml File <?xml version="1.0" encoding="utf-8"?>

Nested Observers with LiveData (Observing an observer)

北战南征 提交于 2021-01-29 05:18:05
问题 I have a case where I have BottomNavigationView where fragments are shown/hidden instead of adding/replacing, therefore they do not go through their lifecycle every time. Fragment 1 is observing one database table, Fragment 2 is observing a different one. My goal is to call the onChanged of Fragment 2 when onChanged of Fragment 1 is called. A stupid and naive solution that worked was to set up the observer of Fragment 1 in Fragment 2 and inside it call another observer: mFragment1ViewModel1

java.lang.IllegalArgumentException: navigation destination {actionId} is unknown to this NavController when Activity is recreated?

有些话、适合烂在心里 提交于 2021-01-29 05:06:23
问题 I am coming from reading all the answers in IllegalArgumentException: navigation destination xxx is unknown to this NavController with no luck. I am getting this when the activity is recreated from either a manual recreate() call or coming back from a process death. I have an Activity that changes its Fragments using Navigation . Fragment A has a FAB that navigates to Fragment B when clicked. floatingActionButton = view.findViewById<FloatingActionButton>(R.id.floating_action_button).apply {

How to pass custom object arraylist from activity to fragment with instance

假如想象 提交于 2021-01-29 02:50:00
问题 I am using viewpager and creating fragments and i want to pass the arraylist. So i have tried the below things: MainActivity: private ArrayList<customers> mArrayList = null; ViewPagerAdapter adapter = new ViewPagerAdapter(MainActivity.this.getSupportFragmentManager()); adapter.addFrag(NewCustomer.newInstance(mArrayList ), "NewCustomer"); Now in fragment class i am creating instance: public static final ArrayList<customers> data = new ArrayList<customers>(); public static final NewCustomer

How to pass custom object arraylist from activity to fragment with instance

寵の児 提交于 2021-01-29 02:49:23
问题 I am using viewpager and creating fragments and i want to pass the arraylist. So i have tried the below things: MainActivity: private ArrayList<customers> mArrayList = null; ViewPagerAdapter adapter = new ViewPagerAdapter(MainActivity.this.getSupportFragmentManager()); adapter.addFrag(NewCustomer.newInstance(mArrayList ), "NewCustomer"); Now in fragment class i am creating instance: public static final ArrayList<customers> data = new ArrayList<customers>(); public static final NewCustomer

SearchView in ActionBar using Fragments

只愿长相守 提交于 2021-01-29 01:31:16
问题 I have a navigation drawer in HomeActivity. Inside the navigation I have fragments that contain different RecycleViews each. I want to implement SearchView in ActionBar so it will search in the RecycleView according to the active fragment. This is on of the fragments code: public class HomeFragment extends Fragment { private static BackEnd backEnd; private RecyclerView rvBooks; private BookAdapter adapter; private MenuItem mSearchAction; private SearchView searchView; private ActionBar