android tabhost - TabActivity and getTabHost() aren't working in my eclipse. How to solve these problems? -


here code

there're problems here

  1. why tabactivity scratch in eclipse?
  2. gettabhost() getting error? can fix code?

i'll try learn androidhive.com see tutorial when write in eclipse, it's failed.

package com.uavero.androidtablayout; import android.os.bundle; import android.app.tabactivity; import android.content.intent; import android.view.menu; import android.widget.tabhost; import android.widget.tabhost.tabspec;  public class tablayout extends tabactivity{ @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_tab_layout);      tabhost tabhost = gettabhost();      // tab photos     tabspec photospec = tabhost.newtabspec("photos");     // setting title , icon tab     photospec.setindicator("photos", getresources().getdrawable(r.drawable.icon_photo_tab));     intent photosintent = new intent(this, photosactivity.class);     photospec.setcontent(photosintent);      // tab songs     tabspec songspec = tabhost.newtabspec("songs");     songspec.setindicator("songs", getresources().getdrawable(r.drawable.icon_song_tab));     intent songsintent = new intent(this, songsactivity.class);     songspec.setcontent(songsintent);      // tab videos     tabspec videospec = tabhost.newtabspec("videos");     videospec.setindicator("videos", getresources().getdrawable(r.drawable.icon_video_tab));     intent videosintent = new intent(this, videosactivity.class);     videospec.setcontent(videosintent);      // adding tabspec tabhost     tabhost.addtab(photospec); // adding photos tab     tabhost.addtab(songspec); // adding songs tab     tabhost.addtab(videospec); // adding videos tab       }   @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.activity_tab_layout, menu);     return true;           }       } 

i can solve problems. android 3.0 , advanced versions not support tabactivity, or if working lower versions , still error occurs change line of code;- tabhost tabhost = gettabhost();, import.app.tabactivity, , tabhost tabhost = (tabhost)findviewbyid(r.id.tabhost).


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -