[英]Expand Expandable Listview in android on button Click
我正在使用其自定義適配器實現可擴展列表視圖。 group元素需要有2個按鈕,首先是父組元素,其下是一個按鈕。
我的問題是,我想單擊下面的按鈕而不是group元素來展開列表視圖。 同樣,組元素onClick
需要調用另一個活動。
我可以通過以下方式禁用expandablelistview的expandablelistview
mainExpListView.setOnGroupClickListener(new OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id)
{
return false;
}
所以我的問題是:
有什么方法可以禁用group元素並使其執行其他功能(例如導航到另一個活動嗎?)
如何在其底部圖像上設置onclick
方法以展開?
this is the groupview of my adapter and expand is the button on which i am performing expand and collapse of my expanded list.
public View getGroupView(final int groupPosition, final boolean isExpanded,
View convertView, final 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.childlist_group, null);
}
TextView lblListHeader = (TextView) convertView.findViewById(R.id.lblListHeader);
ImageView expand = (ImageView) convertView.findViewById(R.id.expand);
if (isExpanded) {
expand.setImageResource(R.mipmap.ic_star_selected);
} else {
expand.setImageResource(R.mipmap.ic_keyboard_arrow_right_black_24dp);
}
expand.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// frag.expandandcollapse(isExpanded,groupPosition);
if (isExpanded) ((ExpandableListView) parent).collapseGroup(groupPosition);
else ((ExpandableListView) parent).expandGroup(groupPosition, true);
}
});
lblListHeader.setText(headerTitle);
return convertView;
}
therefore one more thing to keep in mind u have to override the default expand and collapse of your expandedlistview.........just change the return type of on groupclick listner from false to true
example
ExpandableListView.OnGroupClickListener()
{
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id)
{
String groupNvalue = MyApp.getInstance().categoryNvalues.get(groupPosition);
Showtoast(groupNvalue);
return true;///this has to be changed to true in your activity or fragment
}
});
我不確定,但是在適配器中,您可以在視圖上設置點擊監聽器
@Override
public View getGroupView(int pos, boolean arg1, View convertView, ViewGroup arg3) {
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) act
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.drawerlayout, null);
}
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
})
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.