Is it possible to build one fragment with a listview and a textview inside, so i dont need to add a listfragment and and a DetailFragment. Just one fragment. Because I have only space for one fragment in my activity.
Thanks for youranswers
You don't need to use a List-Activity/Fragment to be able to show a listview. It simply makes it a bit easier for you with functions like getList();
You can just make any normal Activity/Fragment, give your ListView an ID and just fetch it with findViewById(); like you'd do with any other view.
Related
I have one Activity which contains viewpager inside and each viewpager tab contains one fragment . only one of these fragment has one recyclerview (which has inside cardView)and of course one adapter for the recyclerview . by clicking on floating action button which is in Main Activtiy layout another Activity open that contains two edit texts one for device id and one for device name and one button called Add .by clicking the add button it should add the device to the database and update adapter using notifyItemInserted(position) .... the problem here it add the device to the database immediately but the adapter not update the view immediately . it update after i scroll through the app using viewpager tabs or when i start the main activity from the beginning .... there is no error in the code and i have search for answer but i couldn't find anything to solve this issue ..
anyone face like this problem please advice
thanks
Try swapadapter() method for the same.
void swapAdapter (Adapter adapter,
boolean removeAndRecycleExistingViews)
Swaps the current adapter with the provided one. It is similar to setAdapter(Adapter) but assumes existing adapter and the new adapter uses the same RecyclerView.ViewHolder and does not clear the RecycledViewPool.
Have you tried to call your SetUpRecyclerView in onActivityResult() which I asume your are using. That is what I use when adding elements to My RecyclerViews.
When using FragmentPagerAdapter, Your pager keeps two tabs in memory, that's why you have to scroll for the changes to take effect. But for me calling my SetupRecyclerView works just fine.
I have a ListView that represents a list of folders and when I click one item, I want to load another list that shows the content of this folder. How can I link these views together and to be able to go back to the first one with the back button ?
Well, since you didn't provide a code in your question, I will try giving an answer in a descriptive manner.
You can use fragments to do this. Your base Activity's layout must have a fragment container which you will use to display your fragment containing the first ListView data. Once after you click on a cell, you call the constructor of the second ListView, and replace the current content of the fragment container with the newly created fragment.
You may implement a back feature by implementing an ArrayList in your Activity and appending the fragments into that array list as the user navigates through the list. onBack pressed you can call the top most fragment from that Array list and assign it to the fragment container.
This should work well, given there are not too many types of ListViews that you may want to implement.
I have three ListFragment is one activity. For the first listFragment I have created a ListFragment and inflate a layout with some listItem easily:
setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, getResources.getStringArray(R.string.baal)));
The item of the second listFragment will change according to the selected item of the first ListFragment and in the similar way The item of the third listFragment will change according to the selected item of the second ListFragment.
The first ListFragment is static as it won't depend on any other ListFragment. So I simply inflate a layout with some item for it.
But The items of second and third listFragments need to be changed frequently. So I need to inflate it in run-time with new listitems every time on click event. So I think the second and third LisFragment needs to be create dynamically by inflating every-time with new list items. How can I achieve that? I am new in Fragment and I need my concept on dynamic UI clear. Thanks in advance.
You can, for example, try to clear your adapters of second and third fragments and then add all necessary items, this way you would not need to inflate the whole fragments, but instead only the content would change. Also depending on adapter types you would need to call notifyDataSetChanged or not (if it is ArrayAdapter for example).
UPD: On your main item click event you can write some code like this
YourAdapter1 adapter1 = getFirstAdapter();
adapter1.clear();
adapter1.addAll(newItem1Collection);
YourAdapter2 adapter2 = getSecondAdapter();
adapter2.clear();
adapter2.addAll(newItem2Collection);
where YourAdapter1 and YourAdapter2 should extend ArrayAdapter, this will also automatically invoke notifyDataSetChange.
I suggest you use tabs, adding tabs dynamically for each selection, and allowing the user to swipe back to cancel a selection, something like breadcrumbs navigation.
You can see the related question here:
Android - How to create tabs on demand using existing layout?
How to put Expanded List inside a Fragment Tab?
I have 3 fragments in one page, The 2nd Fragment consist of two tabs,I want to put an expanded List inside the second tab.please help ,Thanks :)
Correct me if I am wrong in assuming that you are using ListFragment to show the lists. If you want to use a ExpandableListView you are going to have to implement it yourself inside a normal Fragment since there is no ExpandableListFragment implemented in the APIs.
Here is a link to Android's documentation on how to implement it: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ExpandableList1.html
Hope it helps.
Is it possible to accommodate a Fragments view inside a Gridview. I m unable to find any support with regards to this in the internet.
My basic requirement is i m unaware how many fragments i would be in need i to display wherein the number of fragments would be decided dynamically. Each fragment would contain a separate webviews inside it.
Any sample code would be of great help
Fragment doesn't inherited from View. So its impossible to populate grid with fragments. GridView needs in BaseAdapter which should implement View getView method.
You should write your custom views instead of fragments.
Fragment is independent from view even also from activity .it has life-cycle .I mean you cant make fragment inside GridView. Either you have to make your own custom view by extending gridview .or Use only fragment. Use add and replace to do more ...if you want to play with fragment.
You cannot use GridVew but you have a GridLayout, where fragments can be put