Here is my code
Activity:
@RoboGuice
@EActivity(R.layout.result_page)
public class ResultActivity extends SherlockListActivity implements ActionBar.OnNavigationListener{
@ViewById TextView src;
@ViewById TextView dest;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(src==null || dest==null)
Toast.makeText(this, "@ViewById does not work", Toast.LENGTH_SHORT).show();
//More Code here
}
}
Part of layout: - Note: There are many nested layouts - showing only a part of the layout file
<RelativeLayout
android:id="@+id/topRight"
android:layout_toRightOf="@id/topLeft"
android:layout_height="wrap_content"
android:layout_width="0px"
android:layout_weight="0.8">
<TextView
android:id="@+id/src"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#3399FF"
android:maxLines="1"
android:paddingLeft="8dp"
android:textSize="16dp"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/bottomRight"
android:layout_toRightOf="@id/bottomLeft"
android:layout_height="wrap_content"
android:layout_width="0px"
android:layout_weight="0.8">
<TextView
android:id="@+id/dest"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:maxLines="1"
android:textColor="#3399FF"
android:paddingBottom="10dp"
android:textSize="16dp"/>
</RelativeLayout>
I want to do a setText() on the TextViews. I wonder if my implementing the Interface(which I need) makes the @ViewById to malfuntiion. Or am I missing out something?
Spikas reply is not correct, you dont have to use findViewById when you use @ViewById in android annotations. The thing is that the views have not been injected yet in the onCreate. Try accessing them in a method annotated with @AfterViews, which is guaranteed to be executed after the views have been injected.
for example:
@AfterViews
void checkViews(){
if(src!=null && dest!=null)
Toast.makeText(this, "@ViewById does work!", Toast.LENGTH_SHORT).show();
}