Skip to main content

Posts

Showing posts with the label android-fragments

Best practices to query SQLite database in ListFragment with CursorLoader?

I'm using Android Compatibility Library in my project. I've set up ListFragment as described in the DevGuide ( http://developer.android.com/reference/android/app/Fragment.html ), and using a simple CursorLoader Christian made be used without content provider ( Usage CursorLoader without ContentProvider ). The question is where, in my ListFragment / parent Activity, should I open database, return the Cursor, create Adapter and setListAdapter? So in my app, I have TitlesFragment, DetailsFragment, FragmentLayoutActivity, DetailsLayoutActivity. Is the best practice... to open database in ListFragment's onActivityCreated and close it in ListFragment's onDestroy like in code sample below @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Open database playersDatabaseHelper = new PlayersDBAdapter(getActivity()); playersDatabaseHelper.open(); getLoaderManager()

Keeping ListFragments in a FragmentPager in sync

Let's say I have a list of homogenous items which is likely to be changed in the lifetime of my Activity by user interaction or OS events. The Activity contains a FragmentPager which shows a number of ListFragment s. These fragments share the previously mentioned data but display it in different ways. E.g. they differ in sorting order or display only a subset of the data. Currently each fragment keeps a separate list containing the respective part of the data in the respective order. When the data changes, basicly every fragment has to be updated. This means resorting or adding/removing items from some of the fragments. What is the best practice to keep the data in the different fragments consistent? Currently I have some sort of an observer object, which is notified when something changes and subsequently notifies the connected fragments. But there are a couple of problems: When the app just started, some of the fragments haven't been created by the FragmentPager

How to display 2 different classes (activities) in a fragment in ANDROID?

I have an already working android app, but I need to update it for better layout on tablets. I can rewrite it no-problem, but what I want to ask is; I will have 2 fragments on screen (one for list, and one for details). When I select a customer from list, details will update itself (I have already done this without a problem). BUT, when I select an item from details fragment, it must change itself (it must be opened on details fragment, but of course it will be a different class). For example first details will be a list of details, but when I select an item from details list, it will be a different layout, maybe WebView or so.. To better represent the idea, LLLLLL DDDDDDDDDDDDDDDDDDDDDDDDDD LLLLLL DDDDDDDDDDDDDDDDDDDDDDDDDD LLLLLL DDDDDDDDDDDDDDDDDDDDDDDDDD LLLLLL DDDDDDDDDDDDDDDDDDDDDDDDDD LLLLLL DDDDDDDDDDDDDDDDDDDDDDDDDD LLLLLL DDDDDDDDDDDDDDDDDDDDDDDDDD Where "L" is list fragment, and "D" is details fragment. But I want to show 2 (or more) different cla

android fragments edittext button focus

being new to android app development, I encounter a problem regarding the interaction of android fragments, edittexts, focus and buttons. I have one fragment activity with several tabs. Most tabs have one fragment each. But in one tab, I have a ListFragment and a fragment with edittexts and buttons, which I call edit fragment. When the user selects a list item, the content of the edit fragment is shown in the current tab. When trying to edit a text there, more precisely, when hitting a different key than the backspace key, the new char is not shown, but the first button below gets the focus. Why? And how can I avoid this behavior? Earlier, I had a different activity for the edit fragment and the editing worked perfectly. But for other reasons and because it is recommended, I have only one activity now. Thank you for help! The xml for project_details1: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.andr