gpt4 book ai didi

android - 我想在 ExpandableListView 中为组元素设置可见性

转载 作者:行者123 更新时间:2023-11-30 04:18:40 26 4
gpt4 key购买 nike

在我的 android 应用程序中,我有复选框,在选中复选框时,我想设置 ExpandableListView 组元素的可见性,而且我想将组元素的标题设置为与复选框名称。

 public void onCreate(Bundle savedInstanceState) {
try{
super.onCreate(savedInstanceState);
setContentView(R.layout.detailnewslist);

SharedPreferences settings = getSharedPreferences("mysettings", MODE_WORLD_READABLE);
boolean checkBoxValue1=settings.getBoolean("c1",false);
boolean checkBoxValue2=settings.getBoolean("c2",false);
/*if(checkBoxValue1==true)
{
t1.setText(settings.getString("checkbox", "null"));
}else{t1.setVisibility(View.GONE);}
if(checkBoxValue2==true){
t2.setText(settings.getString("checkbox1", "null"));
}else{t2.setVisibility(View.GONE);}
*/
SimpleExpandableListAdapter expListAdapter =
new SimpleExpandableListAdapter(
this,
createGroupList(), // Creating group List.
R.layout.group_row, // Group item layout XML.
new String[] { "Group Item" }, // the key of group item.
new int[] { R.id.row_name }, // ID of each group item.-Data under the key goes into this TextView.
createChildList(), // childData describes second-level entries.
R.layout.child_row, // Layout for sub-level entries(second level).
new String[] {"Sub Item"}, // Keys in childData maps to display.
new int[] { R.id.grp_child} // Data under the keys above go into these TextViews.
);
setListAdapter( expListAdapter ); // setting the adapter in the list.

}catch(Exception e){
System.out.println("Errrr +++ " + e.getMessage());
}
}

/* Creating the Hashmap for the row */
@SuppressWarnings("unchecked")
private List createGroupList() {

ArrayList result = new ArrayList();
for( int i = 1 ; i < 16 ; ++i ) { // 15 groups........
HashMap m = new HashMap();
m.put( "Group Item","Group I " + i ); // the key and it's value.
result.add( m );
}
return (List)result;
}

/* creatin the HashMap for the children */
@SuppressWarnings("unchecked")
private List createChildList() {

ArrayList result = new ArrayList();
for( int i = 1 ; i < 16 ; ++i ) { // this -15 is the number of groups(Here it's fifteen)
/* each group need each HashMap-Here for each group we have 3 subgroups */
ArrayList secList = new ArrayList();
for( int n = 0 ; n < 5 ; n++ ) {
HashMap child = new HashMap();
child.put( "Sub Item", "Sub Item " + n );
secList.add( child );
}
result.add( secList );
}
return result;
}
public void onContentChanged () {
System.out.println("onContentChanged");
super.onContentChanged();
}
/* This function is called on each child click */
public boolean onChildClick( ExpandableListView parent, View v, int groupPosition,int childPosition,long id) {
System.out.println("Inside onChildClick at groupPosition = " + groupPosition +" Child clicked at position " + childPosition);
return true;
}

/* This function is called on expansion of the group */
public void onGroupExpand (int groupPosition) {
try{
System.out.println("Group exapanding Listener => groupPosition = " + groupPosition);
}catch(Exception e){
System.out.println(" groupPosition Errrr +++ " + e.getMessage());
}
}

最佳答案

ExpandableListView中的关键方法是:

    public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
ViewGroup parent) { ... }

看看如何it is implemented ,例如,在没有 child 时显示/隐藏披露。

关于android - 我想在 ExpandableListView 中为组元素设置可见性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9581373/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com