我有下面的類(包括到另一個類)延伸按鈕機器人,XML佈局
class RecordButton extends Button {
boolean mStartRecording = true;
OnClickListener clicker = new OnClickListener() {
public void onClick(View v) {
onRecord(mStartRecording);
if (mStartRecording) {
setText("Stop recording");
} else {
setText("Start recording");
}
mStartRecording = !mStartRecording;
}
};
public RecordButton(Context ctx) {
super(ctx);
setText("Start recording");
setOnClickListener(clicker);
}
}
按鈕的顯示用下面的代碼是由:
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
LinearLayout ll = new LinearLayout(this);
mRecordButton = new RecordButton(this);
ll.addView(mRecordButton,
new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
0));
setContentView(ll);
}
如何可以定義將按鈕佈局放入.xml文件中而不是在java代碼中執行?
我已經試過了:
<AudioRecordTest.test.RecordButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button"
android:id="@+id/record" />
但它不工作...
非常感謝,
約阿希姆
嘗試使用完整的軟件包名稱(例如,com.joachim.AudioRecordTest.test.RecordButton,或任何您的軟件包) – kcoppock 2011-05-16 22:44:20