我想在單個選擇內顯示圖像,當它出現在對話框內時。單個選擇內的Android圖像
alt text http://www.freeimagehosting.net/uploads/bfb1c90d61.png
我該怎麼辦呢?
我想在單個選擇內顯示圖像,當它出現在對話框內時。單個選擇內的Android圖像
alt text http://www.freeimagehosting.net/uploads/bfb1c90d61.png
我該怎麼辦呢?
在這裏你有工作的解決方案。不是我的,但我用描述的技術,它的工作。不要忘了img.setBounds(),這是必要的!
http://mgmblog.com/2010/06/10/arrayadapter-and-alertdialog-for-single-choice-items/
PS:原帖不顯示的單選按鈕,但我確實佈局。我的單列XML佈局文件(animal_row.xml缺少例子)是在這裏:
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/miastorow_text"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:checkMark="?android:attr/listChoiceIndicatorSingle"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:textColor="#000"
/>
您可以重寫所有內容並從頭開始創建它。首先創建一個描述你想要的內容的XML。例如:
<!-- test.xml -->
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/white">
<ImageView android:id="@+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/facebook"></ImageView>
<TextView android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/ImageView01"
android:text="Facebook"
android:textSize="40sp"></TextView>
<RadioButton android:id="@+id/RadioButton01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/TextView01"></RadioButton>
</RelativeLayout>
然後使用警報對話框構建此xml。您可以讓活動處理您的對話,只是重寫onCreateDialog這樣的:
@Override
protected Dialog onCreateDialog(int id) {
View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.test, null);
return new AlertDialog.Builder(MainActivity.this).setView(view).setTitle("Share")
.create();
}
然後,您可以重寫的onClick的狀態存儲在您StaticPreferences文件。這樣你就可以完全控制視圖中的所有元素。
最後一條建議是,在創建xml時,確保您創建儘可能平坦的佈局,以便優化代碼。你也可以使用列表佈局來創建類似的東西。
錯誤答案,在我的問題提到的佈局,在你的XML佈局你正在相對佈局的單選按鈕,子子,使得單選按鈕除了radiogroup之外的孩子不工作。 在這種情況下,您的答案失敗。 – 2010-07-12 06:18:43
@法埃爾汗:他只是舉了一個例子。 – Macarse 2010-07-17 12:34:41
我沒有爲此工作。但我有一個想法,你已經結合了API演示的三個例子。
你要做的步驟是:
示例代碼:
new AlertDialog.Builder(MainActivity.this).setTitle("Share")setAdapter(new Listadapterclass(),new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface arg0,
int arg1) {
// TODO Auto-generated method stub
// the click event on the list item selected
}})
.create();
希望工程。
不能正常工作,我們如何讓單選按鈕在一個團隊中工作,充氣 – 2010-07-15 16:07:40
真棒,謝謝。 – 2010-07-20 09:53:50