Replace tab with another view - android

I have a TabActivity with a tab, which shows a list. I'd like to display a WebView whenever a list item is clicked. I tried calling listSpec.setContent(R.id.details); but it would not find the resource.
Any clues what I am doing wrong?
UPDATE: I found the following clue from Mark in the mailing list
You don't change the View inside of a tab. You cause the existing View
to show something else (e.g., use FrameLayout and make one layer VISIBLE
and another layer GONE, or use ViewFlipper to swap between contents).
You might be able to get setContent() to replace the current View by
passing in another layout ID or TabContentFactory, but I'm skeptical
this will work.
The tab widget framework in Android is designed for simple stuff. You
may wish to grab the source code for the relevant classes out of Android
and make your own version that handles your own scenario.
--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

I don't know if I'd trust the guy you got your update from. He's...he's...he's...he's balding!
;-)
The most common pattern on Android is for clicking a list item to bring up another activity. If for some reason you don't want that, then the advice I gave in your update is still valid -- you can achieve your effect by hiding the ListView and showing the WebView by one means or another.

Related

Android drag & drop

Before that I start explaining the problem I need to say one thing: I'm totally new to android programming, I can use java without problem, but i still don't know the android packages and classes.
I have a LinearLayout with 2 columns, inside the first column there are some buttons, the second contains a scrollView, in this scrollViewthere should be some... items that the user can add, those items have a title and a text, i already defined thoose objects in another class, and i add them to the scrollViewfrom a button.
From now i put in that object a button that is used to delete the item, but now i realized that it's really ugly, so i was thinking: is it possible to allow the user to drag and drop the item out of the screen to delete it?
I could surely do it by managing the event of pression and release on the item with some listener, but i'm almost sure that there's some android class created for sliding UI components.
Something like what you do with android notification.
I post an image of how the current app is so you can understand better what i said: http://i.stack.imgur.com/fHWK3.jpg (I don't have enough reputation to post images)
If i wasn't clear just say and i will edit with the requested information.
UPDATE: After reading the resource that Bonatti posted in his answer i added a OnLongClickListener for starting the drop, and a OnDragListener to look the cordinates during the drag, now i have a problem... I need my component to be dragged only horizzontally like how you usually remove notification from the notification bar, i thought about the fact that i could save the Y-location of the shadow created by the DragShadownBuilder when i create it, and then i could check in the OnDrag event if the Y-location now is different from the beginning i correct it, but the problem is... how can i access the shadow's location?
The basics of what you are asking for can be found here:
I cant post more than 2 links, so redo these:
http:// developer.android.com/guide/topics/ui/ drag-drop.html
These other might help with what you need in details:
Link 1: code.tutplus Or Link 2: vogella
They both answer what you need.
To put it simple:
You need an "action" to receive that a button/something was pressed (and that is still being pressed), and then update the screen to match the item position

How to implement Tabs UI in android

I have existed code for two activities(ActivityA and ActivityB).
Now I need to have a another activity, which will act as my first and only screen of my application. This activity will be having two tabs on its header part and I need to display each of my Activity when user press on each tab.
I have done some search on this and found TabAcivity will be suitable choice, but it is deprecated now.
I saw many posts which are suggesting Fragments. But I dont want to change my existing code. Can any one suggest me easy method to incorporate this.
you can use Android Tab Layout with Swipeable Views
here i give Link in this link step by step information given. so i think you can get batter idea from that.
Tab Layout with Swipeable Views
you can also download code from this site and also see video in given sit

An alternative to a list of SlidingDrawers

Hi I am developing an application that needs to display list of items. Clicking (or Tapping) on an item should display a description text of the item right below the item. I am talking about something like a vertical accordion.
I want them dynamically created (created in code rather than the XML). That part was completed with ease. I inflated multiple SlidingDrawer in a LinearLayout to accomplish it.
But the problem is only one SlidingDrawer is displayed in the activity. This was accomplished by giving fixed heights to SlidingDrawer. This approach will not hold as I mentioned above that the list of items is dynamically generated and also the area in the activity where the description of the item must come remains blank.
I am now looking for alternative views for accomplishing this. As I am a beginner in Android Development I cant find any that will work in android versions 2.3 and later.
You can always take a look at the SlidingMenu. The project can be found on GitHub. I guess you need to modify the behaviour a bit.

What is the Jelly Bean listview design pattern used by the People app called? How is it built?

Been unable to find anything by googling, probably because I don't know what to call this UI pattern. The JB people app shows contacts on the left, and details for the selected contact on the right. The details fragment on the right has a triangle pointing to the selected contact. What is this Android UI pattern called? How do I implement it.
This is a Master Detail Flow template, which you can get code for if you start a new project and choose to use the MasterDetailFlow template (if you have the latest ADT updates).
As far as the triangle / arrow part goes, I'm not quite sure how Google does it, but this is how I would tackle it:
In the list fragment when an item is selected, it would have an ImageView with the triangle / arrow as its resource that matches the background of the detail fragment, align it to the right of the list row and make sure there is not padding / margin between it and the view's edge. You could either use a ViewStub (http://developer.android.com/reference/android/view/ViewStub.html) or just set the default visibility in the XML of the ImageView to invisible.
Then, in the callback for a list item being clicked, simply inflate or make visible the triangle image in the list row.
I hope this helps. Let me know if you need anything explained in more detail.
Disclaimer: I'm sure this method I've described is not the best / the way Google does it, but this is how I would start trying to implement this feature.

Opening an activity within a View in Android

I've recently started developing Android Apps, and whilst the model is making more sense the more I look at it, I cannot do something (nor find any reference material on it) which to me seems quite simple.
I have an activity which has five buttons along the bottom, and a blank View taking up the rest of the screen. I want, upon clicking these buttons, for an activity to be opened in (and confined to) this view. I can get a new activity running without incident, but this opens in a new screen.
If anyone can show me an easy way to launch a (sub/child?) activity within a view which is defined in the parent activity's layout xml file - equally, it could be created in the parent activity - you'd really be doing me a favor!
I'd recommend taking a look at TabHost. The tabhost is an Activity itself, and the sub-views are all Actvities as well.
Here is a good tutorial that'll get you going very quickly. There is a more work to create (optional) icons for the tabs (also describe in the tutorial).
Hope this helps.
Edit* You mentioned buttons being at the bottom of the screen. Take a look at this SO Question
You can achieve that by using an ActivityGroup... here is a simple example which shows how to do it using a TabActivity:
http://web.archive.org/web/20100816175634/http://blog.henriklarsentoft.com/2010/07/android-tabactivity-nested-activities/
Of course, you will have to change the code since you are not using TabActivities. Just take a look at the getLocalActivityManager and getDecorView methods that is what you will be using.

Categories

Resources