Having trouble with Android 's findViewById -


i'm using pre-generated android code , isn't working.

here oncreateview function fragment:

@override     public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {         view rootview = inflater.inflate(r.layout.fragment_tabmain, container, false);         textview textview = (textview) rootview.findviewbyid(r.id.section_label);         textview.settext(getstring(r.string.section_format, getarguments().getint(arg_section_number)));         return rootview;     } 

here xml fragment:

<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:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context="com.startandselect.agora.tabmain$placeholderfragment">  <textview     android:id="@+id/section_label"     android:layout_width="wrap_content"     android:layout_height="wrap_content" /> 

but when run problem error on textview.settext line because textview null. textview null because line before failed find text view. findviewbyid failed find not know why.

i debugged , found real textview has id: 2131492994 , r.id.section_label has id of 2131492997.

try use following:

textview textview = (textview) findviewbyid(r.id.section_label); 

instead of:

textview textview = (textview) rootview.findviewbyid(r.id.section_label); 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -