I'm using TabHost to display 3 tabs within my application (dashboard, orders and customers). Each of these is a seperate Activity containing a ListView and is working correctly. They all feature an 'endless scrolling' system like within Android Marketplace and retain their positions within the ListView when you switch between different tabs. When you click on an item within the ListView it currently loads up a brand new Activity full screen and leaves the TabHost. I'd like to load up these Activities within the TabHost (eg. Click on a specific customer within the customers list which then takes you to view the customers details whilst remaining within the customers tab. You can then return to the customers list without loosing your position/reloading the list). I've read about ActivityGroup and ViewFlipper but I'm struggling to suss out how to achieve the behaviour I desire.
mTabHost = getTabHost();
mTabHost.setOnTabChangedListener(this);
TabSpec spec;
String Tab_title3 = "NameofTab";
TextView txtTabInfo3 = new TextView(this);
setUpTextView(txtTabInfo3);
txtTabInfo3.setText(Tab_title3);
intent = new Intent();
intent.setClass(this, YourClass.class);
spec = mTabHost.newTabSpec(Tab_title3).setIndicator(txtTabInfo3)
.setContent(intent);
mTabHost.addTab(spec);
So if YourClass is a ListActivity the inside you can put a pop up dialog for example with another List with customer details and then you can add a close button. For your dialog you can setup a custom view a list view with an adapter or something else.
For example in a method:
buildMyDialog(){
final Dialog dialog = new Dialog(this);
lv2=new ListView(this);
lv2.setAdapter(mAdapter2);
//....
final Button cancelButton=new Button(this);
dialog.setContentView(lv2);
dialog.show(
}
Related
I have some Acitivity with a ListView.
I want that after clicking the ListView item there should be new Activity with the same type of layout contains another info(e.g.ListView) related to the clicked item.
I have known that there is not way to create dynamically Activities.
What should I do to be able to go from one Layout to another(by clicking ListView items) and should be able to go back in the same back-sequence by back-key?
I have known that there is not way to create dynamically Activities.
What should I do to be able to go from one Layout to another(by
clicking ListView items) and should be able to go back in the same
back-sequence by back-key?
Why can't you create activities dynamically? You can easily create a new one from your ListView onclick listener
lv.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view, int position, long id){
//Based on the position of the clicked item create a new activity with the position id
Intent intent = new Intent(currentActivity.this, newActivity.this);
intent.putExtra("id", position);
startActivity(intent);
}
};
And now in the newActivity you would check what is the passed id by doing
Bundle bundle = getIntent().getExtras();
theId = bundle.getInt("id");
//Now do something based on that id
Pressing on the back key from the new activity should take you back to the previous one
You can use A Fragment to implements your ListView:
http://developer.android.com/reference/android/app/ListFragment.html
then you can simply replace the current ListFragment with a new one by using the FragmentManager class and the FragmentTransation class. In this way the FragmentManager will take care of replacing the new ListFragment with the old one when you press the back button.
Be careful since if you use ListFragment your SDK target must be 11 or more. If this is a concern for you, you can use the class Fragment from the support library putting inside it a ListView. FragmentManager and FragmentTransation are also part of the support library.
I have created 2 tabs, these 2 tabs individually when on clicked open their respective layouts defined in their activity.
All i want now is to show a different layout on my screen when Tab activity is called. E.g. I don't want to show the content of of the tabs but the content of another layout.
How can i do it?
This is what i was trying to do.
Intent intent1 = new Intent(this, FacebookLoginPage.class);
tabHost.addTab(tabHost.newTabSpec("Facebook").setIndicator("",
res.getDrawable(R.drawable.ic_launcher)).setContent(intent1));
Intent intent2 = new Intent(this, TwitterLoginPage.class);
tabHost.addTab(tabHost.newTabSpec("Twitter").setIndicator("",
res.getDrawable(R.drawable.ic_launcher)).setContent(intent2));
Intent intent3 = new Intent(this, GmaiLoginPage.class);
tabHost.addTab(tabHost.newTabSpec("Gmail").setIndicator("")
.setContent(intent3));
tabHost.setCurrentTab(2);
tabHost.getTabWidget().getChildAt(2).setVisibility(View.GONE);
Is this what you want to do?
Open an activity which shown two tabs and additional information. If one of the tabs is selected then open an activity showing the contents for that tab but not the tabs itself.
In this case consider using a "normal" activity A containing a TabHost and whatever layout you want. If the tab is selected start a new activity B showing the content for that tab. With the back-key navigate back to the first activity A and select the other tab, e.g.
Alternatively you might embed the TabHost (may be as fragment) in activity B also to directly switch between tabs.
Firstly, Im new to android but have years of various other programming experience on unix, windows,but not with Java or android.
Im wanting to display a tab with 3 tabs, each having a different layout file (which works).
Im working on displaying a "blank" template and then the data is retrieved from an XML file once the user points a setting to one (i.e. via shared preferences).
My problem is that the function populateXMLCharacter is never called (using breakpoints). The tab activity always displays "", which is a strig the string.xml.
Actually putting a breakpoint in the oncreate function never gets called either. Ive tried using a call to populateXMLCharacter in onResume, but it too never gets called.
Im thinking its because of the call to the tab:
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
// Do this and the same for all tabs
spec = tabHost.newTabSpec("Description").setIndicator("Description",
res.getDrawable(R.drawable.android)).setContent(R.layout.tab_harp_description);
tabHost.addTab(spec);
Should I be using an intent? I thought the layout was created in a seperate function (in this case harpCSDescription.java and then this allows that activity to be inserted into the tabhost?
other functions:
public class harpcsDescription extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView (R.layout.tab_harp_description);
}
//#Override
protected void onResume()
{
// NOW WE ADD DATA TO THE TEMPLATE
populateXMLCharacter();
}
public void populateXMLCharacter()
{
Ive tried using intents in the following manner but it simply crashes before any breakpoints are reached.
http://developer.android.com/resources/tutorials/views/hello-tabwidget.html
Can some one please guide me to what I should be doing to create an activity with data that is retrieved AFTER the tab is created?
I think you need an intent. To attach an activity to a tab, write the following in the tab host:
Intent intent = new Intent(this, MyActivity.class);
and then in the tab spec write:
tabSpec = tabHost.newTabSpec("name").setIndicator(this.getString(R.string.name)).setContent(intent)
Then in the MyActivity class, you can specify the layout and load the XML data to populate the tab in the onCreate() method. You can use a different activity for each tab.
I am doing application with TabHost activity. I have 5 different class in that 4 class inserted into TabHost view. In one particular class i have list view with onItemclicklistener. while clicking the list view, it goes to different activity(ie 5th class). I want to place the clicked activity in TabHost. (ie) whenever i click the list view, the calling activity should appear in TabHost.But now it appears without tab host. i want to place Tab host in 5 th class by clicking listview. I dont know how to do this, if any one having idea pls let me know and guide me how to do this.
host= (TabHost)findViewById(android.R.id.tabhost);
host.setup();
TabHost.TabSpec spec;
// Create an Intent to launch the first Activity for the tab (to be reused)
Intent i = new Intent().setClass(this, library.class);
spec = host.newTabSpec ("FirstGroup").setIndicator("Library",getResources().getDrawable(R.drawable.imagename)).setContent(i);
host.addTab(spec);
u have to add your all activity like this(here Library)
To put it simply. From a context menu on a TabActivity how can I initiate executing the intent for the current tab? I am trying to force a refresh.
The tabs all initiate activities displaying a subset of people names. While in one list you call up an edit activity which allows you to associate the name to one of the other lists in the TabHost. Using the back button to get back to the tabhost (onResume fires) and the list has not updated. I would like to have a context menu item to refresh the current tab.
I know about using one activity for all the views in a tabhost but for many reasons I have not chosen that method.
You can also try adding a flag to the intent when you set up the tabs in the first place.
Intent i = new Intent().setClass(this, YourClass.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
TabHost.TabSpec spec = tabHost.newTabSpec("name")
.setIndicator("Class",res.getDrawable(R.drawable.ic_tab_something))
.setContent(intent);
Tabhost tabHost.addTab(spec);
I think due to the activity lifecycle, you will have some problems 'restarting' the activity (Activity lifecycle - startActivity()) - if you were to move any logic you have inside the onCreate method into another method, then call the method from onCreate and onResume, so it rebuilds the tab content for you.
Alternatively you could add a menu item to call this method, so onCreate calls the logic method on first run, and your user can call it from the menu to refresh the contents.