欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

ExpandableListView小圖標替換

系統 1826 0
ExpandableListView的小圖標有個狀態,一個是不點擊的情況,一個是點擊后展開的情況,用xml配置如下:
    <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
       <item android:state_expanded="true" android:drawable="@drawable/narrow_select" />
       <item android:drawable="@drawable/narrow" />
</selector>
  

Java的代碼如下:
    ExpandableListView listView = getExpandableListView();
listView.setGroupIndicator(this.getResources().getDrawable(R.drawable.group_icon_selector));
  

注意:不知道為什么,使用自定義的GroupIndicator會發生圖片被拉伸的現象,為了解決這個問題需要定義一個長度為groups.length的boolean數組:
    private boolean[] isOpen=new boolean[groups.length];
  

然后重寫OnGroupCollapseListener和OnGroupExpandListener用于修改當前group的狀態:
    expandableListView.setOnGroupCollapseListener(onGroupCollapseListener);
expandableListView.setOnGroupExpandListener(onGroupExpandListener);
expandableListView.setGroupIndicator(null);//不要自帶的了!!!
OnGroupCollapseListener onGroupCollapseListener=new OnGroupCollapseListener(){

			@Override
			public void onGroupCollapse(int groupPosition) {
				// TODO Auto-generated method stub
				isOpen[groupPosition]=false;
			}
			
		};
		
OnGroupExpandListener onGroupExpandListener=new OnGroupExpandListener(){

			@Override
			public void onGroupExpand(int groupPosition) {
				// TODO Auto-generated method stub
				isOpen[groupPosition]=true;
			}
			
		};

  

最后在getGroupView()中應用,代碼片段如下:
    
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
					View convertView, ViewGroup parent) {
				// TODO Auto-generated method stub
				TextView textView=null;
				if(convertView==null){
					textView=new TextView(mContext);
					AbsListView.LayoutParams lp = new AbsListView.LayoutParams(  
		                    ViewGroup.LayoutParams.FILL_PARENT, 50);  
		            textView.setLayoutParams(lp);
		            textView.setGravity(Gravity.CENTER);
		            textView.setPadding(10, 0, 0, 0);
		            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16.0f);
		            textView.setTextColor(0xFFC6B39C);
		            textView.setBackgroundResource(R.drawable.bg_tv);//bg_tv_expand
		            convertView=textView;
				}else{
					textView=(TextView)convertView;
				}
				//為了處理圖標被拉伸的問題!這里采用偷懶的辦法讓textView傍邊產生一個圖標,如果GroupView只是一個TextView的話,推薦這樣做!
				if(isOpen[groupPosition]){
					Drawable leftDrawable= resources.getDrawable(R.drawable.arrow_down_on);
	            	leftDrawable.setBounds(0, 0, leftDrawable.getMinimumWidth(), leftDrawable.getMinimumHeight());
	            	textView.setCompoundDrawables(leftDrawable, null, null, null);
				}else{
					Drawable leftDrawable= resources.getDrawable(R.drawable.arrow_right_off);
					leftDrawable.setBounds(0, 0, leftDrawable.getMinimumWidth(), leftDrawable.getMinimumHeight());
					textView.setCompoundDrawables(leftDrawable, null, null, null);
				}
				textView.setText(((Market)getGroup(groupPosition)).market);
	            return textView;
}

  


over!

Android版手風琴(ExpandableListView)

創新源于模仿之四:增強的ExpandableListView

android api里的例子:
ExpandableListView小圖標替換
    
import android.app.ExpandableListActivity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;

import com.example.android.apis.R;

/**
 * Demonstrates expandable lists using a custom {@link ExpandableListAdapter}
 * from {@link BaseExpandableListAdapter}.
 */
public class ExpandableList1 extends ExpandableListActivity {

    ExpandableListAdapter mAdapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Set up our adapter
        mAdapter = new MyExpandableListAdapter();
        setListAdapter(mAdapter);
        registerForContextMenu(getExpandableListView());
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
        menu.setHeaderTitle("Sample menu");
        menu.add(0, 0, 0, R.string.expandable_list_sample_action);
    }
    
    @Override
    public boolean onContextItemSelected(MenuItem item) {
        ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo();

        String title = ((TextView) info.targetView).getText().toString();
        
        int type = ExpandableListView.getPackedPositionType(info.packedPosition);
        if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
            int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition); 
            int childPos = ExpandableListView.getPackedPositionChild(info.packedPosition); 
            Toast.makeText(this, title + ": Child " + childPos + " clicked in group " + groupPos,
                    Toast.LENGTH_SHORT).show();
            return true;
        } else if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
            int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition); 
            Toast.makeText(this, title + ": Group " + groupPos + " clicked", Toast.LENGTH_SHORT).show();
            return true;
        }
        
        return false;
    }

    /**
     * A simple adapter which maintains an ArrayList of photo resource Ids. 
     * Each photo is displayed as an image. This adapter supports clearing the
     * list of photos and adding a new photo.
     *
     */
    public class MyExpandableListAdapter extends BaseExpandableListAdapter {
        // Sample data set.  children[i] contains the children (String[]) for groups[i].
        private String[] groups = { "People Names", "Dog Names", "Cat Names", "Fish Names" };
        private String[][] children = {
                { "Arnold", "Barry", "Chuck", "David" },
                { "Ace", "Bandit", "Cha-Cha", "Deuce" },
                { "Fluffy", "Snuggles" },
                { "Goldy", "Bubbles" }
        };
        
        public Object getChild(int groupPosition, int childPosition) {
            return children[groupPosition][childPosition];
        }

        public long getChildId(int groupPosition, int childPosition) {
            return childPosition;
        }

        public int getChildrenCount(int groupPosition) {
            return children[groupPosition].length;
        }

        public TextView getGenericView() {
            // Layout parameters for the ExpandableListView
            AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, 64);

            TextView textView = new TextView(ExpandableList1.this);
            textView.setLayoutParams(lp);
            // Center the text vertically
            textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
            // Set the text starting position
            textView.setPadding(36, 0, 0, 0);
            return textView;
        }
        
        public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
                View convertView, ViewGroup parent) {
            TextView textView = getGenericView();
            textView.setText(getChild(groupPosition, childPosition).toString());
            return textView;
        }

        public Object getGroup(int groupPosition) {
            return groups[groupPosition];
        }

        public int getGroupCount() {
            return groups.length;
        }

        public long getGroupId(int groupPosition) {
            return groupPosition;
        }

        public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
                ViewGroup parent) {
            TextView textView = getGenericView();
            textView.setText(getGroup(groupPosition).toString());
            return textView;
        }

        public boolean isChildSelectable(int groupPosition, int childPosition) {
            return true;
        }

        public boolean hasStableIds() {
            return true;
        }

    }
}


  



Android UI 之實現多級列表TreeView
http://blog.csdn.net/carrey1989/article/details/10227165

ExpandableListView小圖標替換


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!?。?/p>

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 伊人亚洲 | 国产午夜精品AV一区二区 | 波多野结衣在线观看视频 | 久久综合九色综合97欧美 | 一区二区三区国产精品 | 久久久国产99久久国产一 | 婷婷色在线观看 | www.色综合 | 久久99精品亚洲热综合 | 影音先锋欧美资源 | 欧美综合在线观看 | 亚洲伊人久久综合 | 一级毛片私人影院老司机 | 国产精品伊人 | 国内精品伊人久久久影视 | 天天做天天爱天天操 | 成在线人免费视频一区二区三区 | 久久久久国产一区二区三区四区 | 国产一级一级毛片 | 亚洲欧美成人 | 国产精品视频在线观看 | 激情大乳女做爰办公室韩国 | 魔法骑士在线观看免费完整版 | 国产欧美在线观看视频 | 久久影院2018线观看 | 黄色av网站在线观看 | 色综合久久久久久久久五月性色 | 亚洲AV国产精品无码A片 | 日韩成人免费在线视频 | 国产三级在线视频 一区二区三区 | 成人免费观看视频 | 成人自拍在线 | 日韩a | 一区免费看 | 亚洲国产日韩欧美在线 | 久996视频精品免费观看 | 欧美日韩亚洲精品国产色 | 亚洲性一区 | 天天操天天摸天天爽 | 26uuu中文字幕 | 好大好硬好长好爽a网站 |