-3
Button b = new Button(this);
b.setText(m.group());
RelativeLayout.LayoutParams lP = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
int iDELETE_AFTER_TEST_ID;
if(bLast != null){
/*
* Add a new move button
*/
iId = bLast.getId();
lP.addRule(RelativeLayout.RIGHT_OF, iId);
bLast = b;
bLast.setId(iId + 1);
iDELETE_AFTER_TEST_ID = iId + 1;
}else{
/*
* Add the first of the move buttons
*/
bLast = b;
bLast.setId(R.id.base_button_arrangement_id);
lP.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
iDELETE_AFTER_TEST_ID = R.id.base_button_arrangement_id;
}
b.setLayoutParams(lP);
b.setPadding(20, 10, 20, 50);
Log.d(TAG, " going to add = " + b.getId() + " class = " + b.getClass());
rl.addView(b);
mNumberofMoveOptions++;
View v = findViewById(iDELETE_AFTER_TEST_ID);
if(v != null){
if(v.getClass() == Button.class){
Log.d(TAG, " id = " + b.getId() + " class = " + b.getClass());
}else{
Log.e(TAG, "Corruption has occured - not button type: " +
iDELETE_AFTER_TEST_ID + " class: " + v.getClass());
}
}else{
Log.e(TAG, "Corruption has occured - view is null: " + iDELETE_AFTER_TEST_ID);
}
調試:
將添加= 2130968581類=類android.widget.Button
腐敗已發生 - 而不是按鈕類型:2130968581 class:class android.widget.TextView
Question:
So即使調試清楚地顯示了小部件被創建爲Button,但當我直接查詢它時,它已被轉換或更改爲TextView。我是否錯誤地查詢,或ID是否被回收或發生其他事情?
我之前創建的按鈕,在這個特定的工作之前完全正常工作,並且被創建並保持爲Button小部件類型。
非常感謝任何幫助提前。
你的帖子中沒有期號。如果您沒有提出具體問題,我們將無法爲您提供幫助 – pandre
對不起,它不清楚。我已經編輯了這篇文章,以更具體。 – Cullan