I'm new to Java & Android development. I'm trying to develop an app that has 2 tabs, 1 tab has a listview inside of it. When you click on an item in the list, it takes you to another list.. and then you select another item, onto another list, ect.. until they reach the final page which I have setup as a non-selectable list. My question is.. should I create a new activity every time the user clicks on an item in the list? Or is that something normally done with changing views? If done with views, doesn't that pretty much disable their use of going back with the back button?
In the other tab I have an area with a list I guess in which you can remove items off of the list.. Now would I create a new activity for this and put this tab activity on every activity of the lists? I guess this part is what got me confused.. if I hadn't had the other tab my current setup of creating a new activity as the user drills down the lists worked just fine.
This all might sounds a little confusing but let me know if you guys need further explanation..
I would use changeable views only when the views are conceptually showing the same data from a different viewpoint. Since you say "it takes you to another list", I'd say use a separate activity.
As for the tab, my understanding is that you can model each tab as a separate activity, I'm not clear on why you would "put this tab activity on every activity of the lists"? Are you saying that one tab (the "remove" tab) is dependent on what's showing on the other tab ("the list tab")? Without knowing more about the context, but first instinct would be to use a separate "remove tab" activity and model the tab host as having separate activities per tab.
Related
Now I want to create a TabHost for 3 categories, Pizza, Spaghetti and Snack. Information will be taken form database. Is it possible to access only information of that specific category after the tab is clicked instead of creating it when the activity starts. If it is possible, which way is better.
I made something like you over a week ago and after long debugging I realized that the system loads the present tab and the one after it at the same time in case to be ready for swiping anytime you wanna do it (I mean their layouts). So if you place your database logic on the Fragments not on your Activity directly (different database logic on the different tabs), when you load your app, only the first tab database logic will be loaded, but the second tabs layout will be loaded too. Hopefully you could understand what I meant :)
I have a typical dual UI scenario - a list of categories, which when one is clicked, loads a category detail fragment containing a list of items in that category. On the phone, it's implemented as a stack-of-cards UI, opening up the details in a separate activity on top of the category list. On a tablet, it's the category list on the left, with the details on the right.
In the details pane, there's a button to add an item. The details fragment has an interface, required of Activities, with an onClickAddItem method, which should bring up a DialogFragment to ask you for the details of the item and add it when it returns.
The problem: both the tablet version's all-in-one Activity and the phone's standalone details Activity need the same onClickAddItem logic. There's a sinking feeling deep in my gut that the proper solution for this is to pull that logic out into yet another class, but the need to create several million files to do simple things in Android is slowly driving me insane, so I'm hoping there's another best practice I'm overlooking here. Thanks!
If your "add" button is in the detail fragment, there is no reason to handle the click event in the activity.
I think you should put the click event handling in your detail fragment.
Why do you want to keep all database access in the activity ? Make sure you're properly abstracting database access ( using a ContentProvider for example ) and don't be shy to use your abstraction wherever it makes sense. Adding an item using a ContentProvider should be as simple as:
getContentResolver().insert(myUri, myNewItemContentValues);
It you need to display a dialog, just get a reference to the current activity from the detail fragment, and use it to display your dialog.
If several fragments share the same functionality, you may need to write a simple helper class with some methods like:
public void showAddItemDialog(Activity activity)
Good day,
I make my test application in Android and find some difficult moments to do by myself.
I have two Tab Fragments and Host Activity (that creates two tab fragments) with Action Bar (actionbarsherlock). One Fragment allows to add some information about product and persist it into SQLite. Other Fragment has a listview that displays all the products from database.
The problem is that in the first tab I persist data in different thread with 5 second delay, so you click "Add Product to Database" button and after 5 seconds it will be added. But right after clicking I can switch to another tab with listview and the situation is as follows: data from the first fragment is not persisted yet because of delay, but after it is persisted, nothing changes in listview - the listview doesn't know about changes. I need listview updated authomatically when it notices there are changes in database. How can I do this? I use ArrayAdapter to populate data into listview.
I think you need necessary use broadcast receiver, and in it call method refreshDrawableState() for you list. Respectively receiver is your activity.
I am developing an android application in which I have creted a TabActivity. For each tab I am using a separate activity and a separate layout file. Actually this activity is a details screen which shows customer information. The user can click on an item in a listview activity in order to see customer's detailed info in the tab acticity. There he can use navigation buttons to navigate through the customers In a few words, if the listview displays 10 records and the user clicks on the first item the customer details.tabactivity opens and displays detailed info. Using the navigation butons the user can see the next or previous record.
Now, I would like to use a viewflipper in the details screen in order to use animations while navigating through the records and in the end. to use fling gestures instead of buttons. Nevertheless I haven't found a proper example of how to add a tabhost/tabactivity in the flipper. I also thought to create the tabs using one layout in order to add it to the viewflipper but then I have no way to create the tabs inside the activity that hosts the viewfliper.
Any help would be apreciated. Thank you in advance.
ps. I will create a basic app of what I am talking and upload if that would be helpful
The ViewPager may be more appropriate for what you are trying to do.
I'm a newbie Android developer and I'm trying to create an Android application with 2 tabs, using Activities for each tab. This is basically how it should work:
Tab A has 1 button
Tab B has 1 ListView
When the user clicks on the button in Tab A the application must put a value in the ListView in Tab B
My question is: how can I update the ListView in Tab B when I click on the button in Tab A? I know how to put values in a ListView when it's on the same tab where the button is located but my approach doesn't work when the ListView is in a different tab. I tried...
ListView myListInTabB = (ListView)findViewById(R.id.list_on_tabB);
but didn't work :-/
Any suggestion?
Thanks in advance.
Im not sure you actually need seperate activites for this, unless you are doing some specific work between your activities. Most tab solutions you see in Android solutions work simply by hiding the Views that are not related to the current shown tab. You will find the "visibility" property helpful for making this happen. Also, making sure all of your Views are in the same Activity lets you access their objects all the time, regardless of their visibility.
You don't do that. Just ensure the underlying Adapter has the latest data. Calling requery() on the Cursor does the trick, it automatically updates the ListView attached to it.
Edit: use notifyDataSetChanged() to let the list know that the data is stale.