I am trying to make a button. I am always getting a R.id error.
"id cannot be resolved or is not a field."
This line throws the error:
LinearLayout layout = (LinearLayout) findViewById(R.id.layout1);
Every time i try to use something with R. it throws that same error.
If i create a field in R.java class which eclipse recommends
public static Object id;
Then, eclipse highlights .layout1
and the error said "layout1 cannot be resolved or is not a field."
Here is the code:
import android.widget.Button;
Button myButton = new Button(this);
myButton.setText("Press Me");
Finally add the button to the layout:
LinearLayout layout = (LinearLayout) findViewById(R.id.layout1);
layout.addView(myButton);
Any help is much appreciated. Is there a way to drag and drop controls? and why cant i ever use R.id?