How to change the intent in a tabspec after passing an event

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

How to change the intent in a tabspec after passing an event

Postby achie1266 » Wed Dec 02, 2009 8:22 am

I has a tab host with multiple tabs.

My problem is that one of the tabs has a listview and each list item has an onclick listener to display related details.

Right now I am starting a new intent but that removes the tabhost altogether. What i want is the current view/intent of that tabspec should be replaced by the details view without removing the tabs from the view.

How can I implement this? Even a basic example that provides a basic idea will do a lot to help me.

Thank you.
achie
User avatar
achie1266
Master Developer
Master Developer
 
Posts: 223
Joined: Mon Nov 09, 2009 10:56 pm
Location: Denver

Top

Postby achie1266 » Wed Dec 02, 2009 6:11 pm

Can someone help me with this.

this is what I am doing right now from the main list view

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.     protected void onListItemClick(ListView l, View v, int position, long id){
  3.  
  4.         super.onListItemClick(l, v, position, id);
  5.  
  6.         Intent intent = new Intent(this, NewView.class);
  7.  
  8.         startActivity(intent);
  9.  
  10.     }
  11.  
  12.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


This opens the new activity but how can I display the new activity within the tabs . ie., I just want to replace the current list view by another detail view of the item without losing the tabs.
achie
User avatar
achie1266
Master Developer
Master Developer
 
Posts: 223
Joined: Mon Nov 09, 2009 10:56 pm
Location: Denver

Postby Kryex » Thu Dec 03, 2009 8:11 pm

I have exactly the same problem:

I have an application with 3 tabs and with an event on the first tab i want to get some data (two variables) and go to the second tab where i cause them.

How can I do it?


Thanks,
Kryex
Kryex
Freshman
Freshman
 
Posts: 6
Joined: Thu Dec 03, 2009 8:09 pm

Postby achie1266 » Thu Dec 03, 2009 9:15 pm

I was able to create a new intent in the same tab but it is being displayed only when I click on another tab and come back to the earlier tab.

I made the TabHost and tabSpec variable to be static in my main activity class that extends TabActivity.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     public class MyMainActivity extends TabActivity{
  2.  
  3.         static TabHost mTabHost;
  4.  
  5.         static TabHost.TabSpec myTabSpec;
  6.  
  7.  
  8.  
  9.        public void onCreate(Bundle savedInstanceState) {
  10.  
  11.        .................................
  12.  
  13.        }
  14.  
  15.     }
  16.  
  17.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


I am calling these in the other class in an onclick listener

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  Intent intent = new Intent(this, OtherView.class);
  2.  
  3.  MyMainActivity.mytabSpec.setContent(intent);
  4.  
  5.  MyMainActivity.mTabHost.setCurrentTab(0);
  6.  
  7.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


How can I make it to refresh the view as soon as I pass the intent to setContent method?

Thank you
achie
User avatar
achie1266
Master Developer
Master Developer
 
Posts: 223
Joined: Mon Nov 09, 2009 10:56 pm
Location: Denver

Postby Kryex » Thu Dec 03, 2009 9:30 pm

Thanks to the reply above, using "MyMainActivity.mTabHost.setCurrentTab(0); " I managed to change tabs.

But how can I pass data (variables) too?

I would really appreciate if someone answered, it's a bit urgent.

Thanks in advance,
Kryex
Kryex
Freshman
Freshman
 
Posts: 6
Joined: Thu Dec 03, 2009 8:09 pm

Postby achie1266 » Thu Dec 03, 2009 10:05 pm

Kryex wrote:Thanks to the reply above, using "MyMainActivity.mTabHost.setCurrentTab(0); " I managed to change tabs.

But how can I pass data (variables) too?

I would really appreciate if someone answered, it's a bit urgent.

Thanks in advance,
Kryex


You need to do something like this.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. intent.putExtra("myId", id);
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


and in the other intent where you want to handle these you can access them from the savedInstanceState

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. long myId = savedInstanceState != null ? savedInstanceState.getInt("myId") : -1;
  2.                 if(myId == -1){
  3.                         Bundle extras = getIntent().getExtras();
  4.                         myId = extras != null ? extras.getLong("myId") : -1;
  5.                 }
  6.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


Hope it helps you.

If you do find a solution for the question that have asked regarding how to make it show the new intent in the same tab, please help me when you are free.
achie
User avatar
achie1266
Master Developer
Master Developer
 
Posts: 223
Joined: Mon Nov 09, 2009 10:56 pm
Location: Denver

Top

Postby Droid123 » Mon Dec 07, 2009 1:56 pm

I have not tried what you are trying to do before, but I can imagine it's a bit like what I have done.

I have a tabhost with 4 tabs, each tab is populated by an intent, like this:

tabHost.addTab(tabHost.newTabSpec("newTab")
.setIndicator("varname", getResources().getDrawable(R.drawable.icon))
.setContent(new Intent(this, myOtherActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));

So I can image that you would have to call .setContent of your tabhost again and then call invalidate() or redraw or something
Droid123
Experienced Developer
Experienced Developer
 
Posts: 77
Joined: Sat Nov 21, 2009 1:21 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests