I've a problem with some objects in my Android application. I'm pretty newbie so the error might be stupid but I can't see it.
Here the code:
activity_main.xml
<LinearLayout 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"
android:id="@+id/main_page"
android:orientation="vertical"
tools:context=".MainActivity" >
<TextView
android:id="@+id/main_TV"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@str_listen"
android:id="@+id/button_send"
android:onClick="sendMessage" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@str_info"
android:id="@+id/id_info" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@str_credits"
android:id="@+id/id_credits" />
</LinearLayout>
MainActivity.java
package com.example.cartoonia;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn_listen = (Button) findViewById(R.id.id_listen);
Button btn_credit = (Button) findViewById(R.id.id_credits);
Button btn_info = (Button) findViewById(R.id.id_info);
}
/** Called when the user touches the button */
public void sendMessage(View view) {
// Do something in response to button click
TextView tv = (TextView) findViewById(R.id.main_TV);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
I'm using eclipse and usually, when I add an item in the xml file, its id becomes accessible immediately.
The id of the linear layout is accessible, the ids of the other elements added in a second moment aren't. The error shown is, for example, *id_info cannot be resolved or is not a field*
How can I fix it?