我想要創建一個ListView
保存具有CheckBox
和RadioGroup
與2 RadioButtons
列表項目。ListView與RadioGroup不顯示
我不知道爲什麼,但TextView
的和CheckBox
顯示,而RadioGroup
不是。
我查過這個問題,但找不到這個確切的問題。誰能幫我?
這是XML代碼:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:id="@+id/hlInteraction"
android:layout_alignParentBottom="true"
android:background="@android:color/darker_gray" />
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/hlInteraction"
android:orientation="horizontal"
android:gravity="center"
android:id="@+id/rgInteraction"
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="@string/rb_on"
android:id="@+id/rbTurnOff"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="16dp"
android:paddingLeft="16dp"
android:text="@string/rb_off"
android:id="@+id/rbTurnOn"
/>
</RadioGroup>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tvDeviceNameInteraction"
android:layout_alignParentLeft="true"
android:paddingLeft="16dp"
android:textSize="24sp"
android:layout_above="@id/rgInteraction"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tvDeviceDistanceInteraction"
android:layout_toRightOf="@id/tvDeviceNameInteraction"
android:paddingLeft="16dp"
android:textSize="24sp"
android:layout_above="@id/rgInteraction"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingRight="4dp"
android:id="@+id/cbInteraction"
android:layout_above="@id/rgInteraction"
/>
這裏是習俗adatper類:
public class InteractionAdapter extends ArrayAdapter<Interaction>
{
private ArrayList<Interaction> mList;
private Context mContext;
/*
* Creates the Adapter for the list
*/
public InteractionAdapter(Context context, int layoutId, ArrayList<Interaction> list)
{
super(context,layoutId,list);
mList = list;
mContext = context;
}
/**
* inflate view for each row
*/
@SuppressLint("InflateParams")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
Interaction current = mList.get(position);
/* if the given channel row view is not being updated*/
if (v == null) {
/* inflate layout */
LayoutInflater vi = LayoutInflater.from(getContext());
v = vi.inflate(R.layout.list_item_interaction, null, false);
}
/*get the component pointers */
TextView tvInteractionDeviceName = (TextView) v.findViewById(R.id.tvDeviceNameInteraction);
TextView tvInteractionDeviceDistance = (TextView) v.findViewById(R.id.tvDeviceDistanceInteraction);
RadioButton rbOn = (RadioButton) v.findViewById(R.id.rbTurnOn);
RadioButton rbOff = (RadioButton) v.findViewById(R.id.rbTurnOff);
rbOn.setChecked(true);
CheckBox cbInteraction = (CheckBox) v.findViewById(R.id.cbInteraction);
Device d = current.getDevice();//Gets Device object and then BluettothDevice object
tvInteractionDeviceName.setText(d.getDevice().getName());
tvInteractionDeviceDistance.setText(String.valueOf(d.getRSSI()));
return v;
}
另外,如果我想獲得RadioButton
SI的狀態基本上需要爲他們添加標籤作爲標籤的一種形式,以便我可以區分彼此。對?
編輯
佈局似乎是在我剛剛發佈了XML代碼給你看預覽是工作的罰款。我懷疑這部分代碼中有任何錯誤。
這裏有一個畫面:
我已經發布了一個新的答案,這段代碼正在運行。 –