How can we change the view of the tabs?

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

How can we change the view of the tabs?

Postby achie1266 » Fri Dec 11, 2009 1:21 am

I have asked the same thing a few days back but could not get a working solution, so here I am again struck at this point.

I want to provide a clickthrough on the list in a tab which opens another view.
I need to open the new view within the same tab. I then need to provide a back button on the changed layout to change the view to original view.

I have tried this.
I am trying to access the tabSpec from main activity class[MainTabView] and set the intent as follows.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. MainTabView.tabSpec1.setContent(new Intent(this, AView.class));
  2.  
  3. MainTabView.mTabHost.setCurrentTab(0);
  4.  
  5. MainTabView.mTabHost.invalidate();
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

But this does not change the view immediately but changes it when I go to another tab and come to the starting tab. How can I make it to refresh it as soon as the content has been changed to another intent?

Please share your ideas on this. Alternative solutions/ideas are also welcome.

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

Top

Postby sandis84 » Fri Dec 11, 2009 10:23 am

To be honest I did not understand exactly what you want to do. But as I understood, it was related to changing a layout before it is displayed? I know that I have had very much problem with this, but I have found solutions to it.

The thing is that graphical changes often wont happen until the activity-thread stop being busy with your current function (since there can only be one ui-thread). So if you both change a layout and display it in the same function, it will be displayed before it is changed. What you can do is instead of displaying the function, send a message to a Handler. The Handler can then display the layout/popup/whatever. Hopefully I have not missunderstood you and this will solve your problem. :)

Cheers,
sandis84
Experienced Developer
Experienced Developer
 
Posts: 78
Joined: Fri Aug 07, 2009 3:54 pm

Postby achie1266 » Fri Dec 11, 2009 4:56 pm

Hi Sandis84,

sorry that I was not clear,

What I was trying is to implement an onClick listener on one of the view items in a tab.
Say my layout in one of the tabs is a list and I want to implement onListItemClick and handle it to replace the list with another view with details of the clicked item.

I could have posted the entire code but it includes out company biz logic. So I am recreating the problem with another sample project and will post it too if you think you want to check it.

I cannot use a popup in this case as i need to provide more clickthroughs even from the second view and our business requirements are fixed on that :-(

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

Postby achie1266 » Fri Dec 11, 2009 7:23 pm

I have made this as a mini project and am attaching the entire code.
It has a self generating employees list that will be pushed into database.
The listAdapter will fetch those employees tp populate the list.

if you setup this project you will observe that when clicking on eny employee in Tab B it doesnot refresh the view but when you come back to the tab after clicking on another tab it messes up the view in all the tabs.

Here is the code form my listActivity class
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         AchieDbAdapter adapter;
  3.  
  4.         private MyAdapter1 myAdapter1_1;
  5.  
  6.         private ArrayList<Employee> employees = null;
  7.  
  8.        
  9.  
  10.         @Override
  11.  
  12.         protected void onCreate(Bundle savedInstanceState) {
  13.  
  14.                 super.onCreate(savedInstanceState);
  15.  
  16.                 setContentView(R.layout.main_list2);
  17.  
  18.                
  19.  
  20.                 adapter = new AchieDbAdapter(this);
  21.  
  22.                 adapter.resetData();
  23.  
  24.                
  25.  
  26.                 employees = adapter.fetchEmployees();
  27.  
  28.                 this.myAdapter1_1 = new MyAdapter1(this, R.layout.row_1, employees);
  29.  
  30.                 setListAdapter(myAdapter1_1);
  31.  
  32.                
  33.  
  34.         }
  35.  
  36.    
  37.  
  38.     protected void onListItemClick(ListView l, View v, int position, long id){
  39.  
  40.         super.onListItemClick(l, v, position, id);
  41.  
  42.         Log.v(this.getClass().getName(), " Position: "+position+", id: "+id);
  43.  
  44.        
  45.  
  46.         Intent i = new Intent(this, Detail.class);
  47.  
  48.         i.putExtra("id", (int)id);
  49.  
  50.         TabMain.tabSpecB.setContent(i);
  51.  
  52.         TabMain.mTabHost.setCurrentTab(1);
  53.  
  54.         TabMain.mTabHost.invalidate();
  55.  
  56.         }
  57.  
  58.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


How do I get rid of this bug and change the views?

thank you.
Attachments
TabSampleForPosts.zip
Entire sample project. copy into eclipse and run to test it.
(77.18 KiB) Downloaded 52 times
achie
User avatar
achie1266
Master Developer
Master Developer
 
Posts: 223
Joined: Mon Nov 09, 2009 10:56 pm
Location: Denver

Postby pratik goswami » Fri Jan 22, 2010 10:44 am

Hi,

Have you resolved problem? I am also looking for the solution.

Thanks
Pratik
pratik goswami
Junior Developer
Junior Developer
 
Posts: 19
Joined: Mon Sep 22, 2008 2:54 pm

Postby achie1266 » Fri Jan 22, 2010 5:27 pm

yes but not exactly in the way that I wanted it to work.

I added each page as a layout inside a frame layout and brought the necessary frame to come to the front as and when required.

But keep in mind that you will have to take care of the orientation changes if you do in this way. Because each time the orientation of the phone changes, Since the activity restarts, it always displays the initial Frame.

What I did after all that was to just go with the options menu and have each tab as a menu item in the options menu.
achie
User avatar
achie1266
Master Developer
Master Developer
 
Posts: 223
Joined: Mon Nov 09, 2009 10:56 pm
Location: Denver

Top

Postby pratik goswami » Sat Jan 23, 2010 6:11 am

Hi,

Thanks for quick response.

Can we use activitygroup for tab purpose? Have a look at these threads -

1, 2 and 3

Thanks
Pratik
pratik goswami
Junior Developer
Junior Developer
 
Posts: 19
Joined: Mon Sep 22, 2008 2:54 pm

Postby achie1266 » Sat Jan 23, 2010 7:36 am

Sorry Pratik,

I cannot be of much help to you in that direction as I still need to work on that advanced stuff.
Hope someone else will answer you.
achie
User avatar
achie1266
Master Developer
Master Developer
 
Posts: 223
Joined: Mon Nov 09, 2009 10:56 pm
Location: Denver

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests