Using tabs, can do better?

Put your problem here if it does not fit any of the other categories.

Using tabs, can do better?

Postby dvd » Tue Mar 08, 2011 3:58 pm

Hello guys,

I need for my application a tabview with 4 tabs.
Each tab represent a status of a document (Draft, Finished, Synchronized and Archived).
All I want to do when clicking on a tab is search in my DB the documents with the good status.
Am I doing it right, or is it a better way to do it ?

The first thing that annoys me is that when the activity begins, the list is empty.
I am forced to switch tab and quickly return to the first tab...

Then, I don't know if I use correctly the list and the tabs...

Thanks!

My onCreate :
Code: Select all
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.history_tabs);
        TabHost.TabSpec spec;
        //Resources res = getResources();

        linearBottom = (LinearLayout) findViewById(R.id.LinearBottom);
        Button changeStatusButton = (Button) findViewById(R.id.ButtonStatus);
        Button deleteButton = (Button) findViewById(R.id.ButtonDelete);
       
        changeStatusButton.setOnClickListener(new View.OnClickListener() {         
         @Override
         public void onClick(View v) {
            changeMultiStatusPopup();
         }
      });
       
        deleteButton.setOnClickListener(new View.OnClickListener() {         
         @Override
         public void onClick(View v) {
            purgeWarning();
         }
      });
       
//        progress = new ProgressDialog(this);
//        progress.setTitle("Loading list, please wait...");
       
       
        tabHost = getTabHost();

        spec = tabHost.newTabSpec("pending").setIndicator("Drafts")
        .setContent(R.id.ListView01);
      tabHost.addTab(spec);
      //tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 40;
      
      spec = tabHost.newTabSpec("finished").setIndicator("Finished Not Synchronized")
      .setContent(R.id.ListView01);
      tabHost.addTab(spec);
      
      spec = tabHost.newTabSpec("synchronized").setIndicator("Synchronized")
      .setContent(R.id.ListView01);
      tabHost.addTab(spec);
      
      spec = tabHost.newTabSpec("deleted").setIndicator("Archived")
      .setContent(R.id.ListView01);
      tabHost.addTab(spec);
      
      tabHost.setOnTabChangedListener(new OnTabChangeListener() {
         @Override
         public void onTabChanged(String tabId) {
            Log.d(LOG, "tab changed for "+tabId);
            if(tabId.contains("pending")){
               changeStatus(Pied.STATUS_DRAFTED);
            }else if(tabId.contains("synchronized")){
               changeStatus(Pied.STATUS_SYNCHRONIZED);
            }else if(tabId.contains("finished")){
               changeStatus(Pied.STATUS_FINISHED);
            }else if(tabId.contains("deleted")){
               changeStatus(Pied.STATUS_ARCHIVED);
            }
         }
      });
      
      
       l = (ListView) findViewById(R.id.ListView01);
       //l = new ListView(this);
       l.setClickable(true);
       
        list = new ArrayList<Pied>();
       
        adapter = new PiedListAdapter(this, R.layout.history_list, list);
        l.setAdapter(adapter);
        //registerForContextMenu(l);
       
        new Thread(new Runnable() {   
         @Override
         public void run() {
            mHandler.sendEmptyMessage(PRELOAD);
         }
      }).start();
       
       
        //Different method... not optimal
        /*
        final TabHost tabHost = getTabHost();
        tabHost.addTab(tabHost.newTabSpec("draft")
                .setIndicator("Drafts")
                .setContent(this));
        tabHost.addTab(tabHost.newTabSpec("finished")
                .setIndicator("Ready")
                .setContent(this));
        tabHost.addTab(tabHost.newTabSpec("synced")
                .setIndicator("Synchronized")
                .setContent(this));
        tabHost.addTab(tabHost.newTabSpec("archived")
                .setIndicator("Archived")
                .setContent(this));
                */
    }


My changeStatus method : (long story short, I reload the list with the documents according to the tab)
Code: Select all
   private void changeStatus(int status){;
       adapter.clear();
       adapter.getFilter().filter("");
      Log.d(LOG,"changeStatus "+status);
       PiedDAO dao = new PiedDAOImpl(this);
       list.addAll(dao.getPieds(status));
       //list = dao.getPieds(this, status);
       adapter.notifyDataSetChanged();
       Log.d(LOG,"changeStatus "+status+" list size "+list.size()+" list id "+list);
       //adapter.notifyDataSetChanged();
       current_status=status;   
       //mHandler.sendEmptyMessage(LIST_LOADED);
   }
dvd
Freshman
Freshman
 
Posts: 4
Joined: Tue Mar 08, 2011 3:24 pm

Top

Re: Using tabs, can do better?

Postby JoxTraex » Wed Mar 09, 2011 3:40 am

once thing you can do is set the tabhost to know WHICH tab to open first. Then after that tab has been set use content view and update it as necessary.
JoxTraex
Developer
Developer
 
Posts: 25
Joined: Wed Jan 26, 2011 12:29 am

Re: Using tabs, can do better?

Postby dvd » Thu Mar 10, 2011 11:28 am

Thank you!
dvd
Freshman
Freshman
 
Posts: 4
Joined: Tue Mar 08, 2011 3:24 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google Feedfetcher and 17 guests