Подумайте, что у меня много занятий, и все, что мне нужно, это:
У меня есть кнопка, определенная в файле с именем test.xml.
Я хочу показать эту кнопку водно из моих занятий, НО только эта кнопка, а не весь test.xml.
Здесь у меня проблема, потому что я сделал новую кнопку, подобную этой:
final Button button = (Button) findViewById(R.id.aboutbutton);
Но я простоне знаю, как отобразить только эту кнопку, а не дыру test.xml.Я искал на сайте Android, но из того, что я видел, он показывает XML-файл дыры, а не только 1 кнопку от него ... так что это не то, что мне нужно ...
И чтоне так с этим кодом?ошибки: метод onCreate (Bundle) не определен для типа View Gameview.java
Метод onCreate (Bundle) типа Gameview должен переопределить метод суперкласса Gameview.java
public class Gameview extends View{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.aboutbutton);
}
private final Game game;
public Gameview(Context context) {
super(context);
this.game = (Game) context;
setFocusable(true);
setFocusableInTouchMode(true);
// TODO Auto-generated constructor stub
}
@Override
protected void onDraw(Canvas canvas) {
// Draw the background...
Paint background = new Paint();
background.setColor(getResources().getColor(
R.color.background));
canvas.drawRect(0, 0, getWidth(), getHeight(), background);
final Button button = (Button) findViewById(R.id.aboutbutton);
}
}
** Я исправил код, как вы сказали, но теперь все ошибается.Большинство из них можно исправить, но ondraw ...:
aboutbutton cannot be resolved or is not a field Gameview.java
The constructor Activity(Context) is undefined Gameview.java
The method getHeight() is undefined for the type Gameview
The method getWidth() is undefined for the type Gameview
The method onDraw(Canvas) of type Gameview must override a superclass method Gameview.java
The method requestFocus() is undefined for the type Gameview Game.java m
The method setContentView(int) in the type Activity is not applicable for the arguments (Gameview) Game.java
The method setFocusable(boolean) is undefined for the type Gameview
The method setFocusableInTouchMode(boolean) is undefined for the type Gameview Gameview.java**