0
我想補充的radiobuttons
的擴張listview
programmatically
從可擴展列表視圖適配器訪問活動內childview項目編程
的radiogroup
裏面我加入需要的視圖(即radiogroup
等)的新linearlayout
和內想要訪問可擴展的listchild
項目的linearlayout
,以便添加的視圖添加到可擴展的listchild
項目中。 請幫助我訪問可擴展listchild
項目XML中的linearlayout
。
這是我PollListAdapter
類
public class PollsListAdapter extends BaseExpandableListAdapter {
private Context _context;
private List<String> _listDataHeader; // header titles
// child data in format of header title, child title
private HashMap<String, List<LinearLayout>> _listDataChild;
TextView title;
public RadioGroup rg;
Button b;
public PollsListAdapter(Context context, List<String> listDataHeader,
HashMap<String,List<LinearLayout>> listChildData) {
this._context = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listChildData;
}
@Override
public Object getChild(int groupPosition, int childPosititon) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition)).get(childPosititon);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
// final String childText = (String) getChild(groupPosition, childPosition);
View v=convertView;
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.polls_item, null);
}
title = (TextView) v.findViewById(R.id.title);
// rg=(RadioGroup)v.findViewById(R.id.rg);
// b=(Button)v.findViewById(R.id.submit);
Log.i("childview",title.getText().toString()+rg.getChildCount()+b);
// TextView txtListChild = (TextView) convertView.findViewById(R.id.lblListItem);
// txtListChild.setText(childText);
return v;
}
@Override
public int getChildrenCount(int groupPosition) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition)).size();
}
@Override
public Object getGroup(int groupPosition) {
return this._listDataHeader.get(groupPosition);
}
@Override
public int getGroupCount() {
return this._listDataHeader.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.polls_header, null);
}
TextView lblListHeader = (TextView) convertView.findViewById(R.id.header);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle);
return convertView;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
這是我的活動類
listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String,List<LinearLayout>>();
top250 = new ArrayList<LinearLayout>();
expListView = (ExpandableListView) findViewById(R.id.lvExpz);
listAdapter=new PollsListAdapter(this,null,null);
// mLinearLayout = (LinearLayout)findViewById(R.id.ll);
mLinearLayout = new LinearLayout(this);
for (int k = 1; k < a; k++) {
//create text button
TextView title = new TextView(this)
listDataHeader.add(title.getText().toString());
final RadioButton[] rb = new RadioButton[b];
RadioGroup rg = new RadioGroup(this);
rg.setOrientation(RadioGroup.VERTICAL);
for (int i = 0; i < b; i++) {
rb[i] = new RadioButton(this);
rg.addView(rb[i]);
rb[i].setText("i");
rb[i].setVisibility(View.VISIBLE);
}
mLinearLayout.addView(rg);
top250.add(mLinearLayout);
listDataChild.put(listDataHeader.get(k-1),top250);
listDataChild.values();
expListView.setAdapter(new PollsListAdapter(this, listDataHeader, listDataChild));
main.xml中包含expandablelist和
的polls_item.xml是
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10sp"
android:layout_marginRight="10sp"
android:layout_marginTop="10sp"
android:layout_marginBottom="10sp"
android:background="@drawable/polls_single_border"
android:orientation="vertical" >
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="title"
/>
<RadioGroup
android:id="@+id/rg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
我被困在它三天親切地幫助我pl z。
據我從你的代碼明白的是你正在使用列表視圖擴展,以擴展列表視圖,你可以有小孩和組不同的看法...請訪問此鏈接http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/如果你鋼發現任何困難,然後讓我知道 –
是的,我知道有不同的孩子和團體觀看我面臨的scenerio是,我不知道如何訪問可擴展組視圖內的childview項目 – mominapk