私はサブクラスButton
にしようとしましたが、私はプロジェクトを起動するときに多くのエラーがあります。あなたは見て、これを修正する方法を教えていただけますか?Androidのサブクラスボタン:多くのエラー
package my.project.name;
import android.app.Activity;
import android.os.Bundle;
public class MyProjectActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
とxml::
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<MyButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/myb"
android:tag="tag"
/>
</LinearLayout>
EDIT:
package my.project.name;
import android[...]
public class MyButton extends Button {
public MyButton(){
super(null);
}
public MyButton(Context context){
super(context);
}
public MyButton(Context context, AttributeSet attrs){
super(context, attrs);
}
public MyButton(Context context, AttributeSet attrs, int defStyle){
super(context, attrs, defStyle);
}
@Override
protected void onDraw(Canvas canvasObject) {
super.onDraw(canvasObject);
int x = 100;
int y = 100;
int width = 80;
int height = 200;
Paint thePaint = new Paint();
thePaint.setColor(Color.WHITE);
RectF rectangle1 = new RectF(x,y,x+width,y+height);
canvasObject.drawRoundRect(rectangle1, 10.0f, 10.0f, thePaint);
}
}
メインクラスを(私は多分50のエラーが来るんだ)実際に、矩形は表示されません。私はエラーがないので、サブクラスは動作しますが、 "@ null"の背景でさえ、四角形は表示されません。
どうもありがとう
うーん、何のエラー?それは重要なディテールのようなものです。あなたがXMLであなたのボタンの完全修飾名を使用しなければならないことがわかりました。 (例: 'my.project.name.MyButton') – kcoppock
i!= I ......... – Shoban
受け取ったエラーのいくつかを追加してください。また、XMLに完全修飾名前空間を記述する必要があります。 のように –