Ausweitung der Button-Klasse
Bitte helft mir mein problem zu lösen. Ich versuche eine Schaltfläche erstellen, die mit einigen zusätzlichen Funktionen. Aber wenn ich verlängern Klasse Button, ein rendering-problem angezeigt :"der Benutzerdefinierte Ansicht GameButton ist nicht mit dem 2 - oder 3-argument-Ansicht Konstruktoren; XML-Attribute nicht funktionieren wird". Ich habe wirklich keine Ahnung, wo das problem ist, da ich alle Konstruktoren zu meiner Klasse GameButton:
package ua.oksana.sendev.tictactoe
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.*;
public class GameButton extends Button {
private int parentId;
private int cellId;
public GameButton(Context context) {
super(context);
}
public GameButton(Context context, AttributeSet attrs) {
super(context, attrs);
}
public GameButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.L)
public GameButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public void setParentId(int parentId){
this.parentId=parentId;
}
public void setCellId(int cellId){
this.cellId=cellId;
}
public int getParentId(){
return this.parentId;
}
public int getCellId(){
return this.cellId;
}
}
Und XML:
<ua.oksana.sendev.tictactoe.tools.GameButton
style="@style/cellStyle"
android:id="@+id/button99"
android:layout_column="3" />
Stil:
<style name="cellStyle">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:buttonStyle">?android:attr/buttonStyleSmall</item>
<item name="android:layout_weight">1</item>
</style>
Du musst angemeldet sein, um einen Kommentar abzugeben.
Fügen Sie diese Zeile in Ihre Schaltfläche xml -
Als unten und Versuchen, ob das funktioniert