これを行うためにボタン クラスを拡張する必要はありません。
私があなただったら、おそらくカスタム ビューを作成することさえしないでしょう。その中に 2 つの TextView を含む LinearLayout を使用するでしょう。線形レイアウトの背景は、円の png に設定します。
このようなものがxmlになります。
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/circle"
android:orientation="vertical"
android:id="@+id/circleLyt">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/nameTxt"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/countTxt"
/>
</LinearLayout>
必ず circle.png をdrawable
フォルダーに入れてください。これらすべてのビューへの参照を取得するfindViewById();
には、TextViews への参照を取得したら、テキストを必要なものに設定できます。また、LinearLayout リファレンスを使用すると、ボタンの場合とまったく同じ方法でクリック リスナーを設定できます。
このようなものはうまくいきます:
mCircleView = (LinearLayout)findViewById(R.id.circleLyt);
mCircleView.setOnClickListener(new OnClickListener() {
public void onClick(View v){
//do some stuff!
}
});
このレイアウトを独自の xml ファイルとして作成し、Adapter を使用して、おそらくGridViewのようなこれらの円で他の構造を埋めることもできます。ビューを膨らませて、アダプタの getView() メソッド内にテキストを入力するだけです。