java - Why do I get an "Your TabHost must have a TabWidget whose id attribute is 'android.R.id.tabs'" error? -
i new in android studio development , errors have messed day. looking solution 2 days many people had same problem me each 1 of them had different solution. in stackoverflow solutions varied, appreciate if me overpass error can go on.
the error getting this:
java.lang.runtimeexception: tabhost must have tabwidget id attribute 'android.r.id.tabs'
i have modified .xml file , .java file lot no chance.
here .xml:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:paddingbottom="@dimen/activity_vertical_margin" tools:context=".mainactivity" android:clickable="true"> <tabhost android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@id/tabhost" android:layout_alignparentbottom="true" android:layout_alignparentstart="true"> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <tabwidget android:id="@+id/tabshost" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"></tabwidget> <framelayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="match_parent"> <linearlayout android:id="@+id/creatortab" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancelarge" android:text="contact creator" android:id="@+id/contactcreator" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" /> <edittext android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputtype="textpersonname" android:text="name" android:ems="10" android:id="@+id/name" android:layout_below="@+id/contactcreator" android:layout_alignparentstart="true" android:layout_margintop="34dp" android:layout_alignparentend="true" android:hint="name" /> <edittext android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputtype="phone" android:ems="10" android:id="@+id/phone" android:layout_below="@+id/name" android:layout_alignparentstart="true" android:layout_alignend="@+id/name" android:hint="phone" android:text="phone" android:layout_margintop="44dp" /> <edittext android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputtype="textemailaddress" android:ems="10" android:id="@+id/email" android:layout_below="@+id/phone" android:layout_alignparentstart="true" android:layout_alignend="@+id/phone" android:text="e-mail" android:layout_margintop="54dp" android:hint="email" /> <button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="add contact" android:id="@+id/addcontact" android:enabled="false" android:allowundo="false" android:clickable="false" android:hint="add contact" android:nestedscrollingenabled="false" android:layout_alignparentbottom="true" android:layout_alignparentstart="true" android:layout_margintop="74dp" /> <edittext android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputtype="textpostaladdress" android:ems="10" android:id="@+id/address" android:text="address" android:layout_above="@+id/addcontact" android:layout_alignparentstart="true" android:layout_margintop="64dp" android:layout_alignend="@+id/email" android:hint="address" /> </linearlayout> <linearlayout android:id="@+id/listtab" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"></linearlayout> </framelayout> </linearlayout> </tabhost> </relativelayout>
and .java:
edittext nametxt, phonetxt, emailtxt, addresstxt; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); nametxt = (edittext)findviewbyid(r.id.name); phonetxt = (edittext)findviewbyid(r.id.phone); emailtxt = (edittext)findviewbyid(r.id.email); addresstxt = (edittext)findviewbyid(r.id.address); tabhost tabhost = (tabhost) findviewbyid(r.id.tabhost); tabhost.setup(); tabhost.tabspec tabspec = tabhost.newtabspec("creator"); tabspec.setcontent(r.id.creatortab); tabspec.setindicator("creator"); tabhost.addtab(tabspec); tabspec = tabhost.newtabspec("list"); tabspec.setcontent(r.id.listtab); tabspec.setindicator("list"); tabhost.addtab(tabspec); final button addbtn = (button)findviewbyid(r.id.addcontact); addbtn.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { toast.maketext(getapplicationcontext(), "your contact has been added", toast.length_short).show(); } }); nametxt.addtextchangedlistener(new textwatcher() { @override public void beforetextchanged(charsequence s, int start, int count, int after) { } @override public void ontextchanged(charsequence s, int start, int before, int count) { addbtn.setenabled(!nametxt.gettext().tostring().trim().isempty());//if nametxt equals nothing, //to trim koitaei gia kena pisw kai mprosta } @override public void aftertextchanged(editable s) { } }); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); //noinspection simplifiableifstatement if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); }
}
i appreciate recommendations.
your error (your tabhost must have tabwidget id attribute 'android.r.id.tabs'
) says all:
change this
<tabwidget android:id="@+id/tabshost" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"></tabwidget>
to
<tabwidget android:id="@+id/android.r.id.tabs" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> </tabwidget>
Comments
Post a Comment