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

自定義PopupWindow1

系統(tǒng) 1632 0
什么都不多說(shuō),看圖先:

自定義PopupWindow1

點(diǎn)擊文本框,彈出最下面的PopupWindow。
很簡(jiǎn)單的啦,不解釋。源碼:
    
package com.dl.view;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.GridView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.dl.app.R;

public class NumbersPickerPopupWindow extends PopupWindow{
	private Context context;
	private String[] balls=new String[]{"0","1","2","3","4","5","6","7","8","9"};
	private final String split=" "; 
	private Button btn_ok;
	private String selectedNumbers;
	private String[] selectedNumbersArray;
	private GridViewAdapter adapter;
	public NumbersPickerPopupWindow(Context context,View view,String title,String selectedNumbers){
		super(view, LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT, true);
		this.context=context;
		this.selectedNumbers=selectedNumbers;
		selectedNumbersArray=selectedNumbers.trim().split(split);
		this.setBackgroundDrawable(new BitmapDrawable());//必須設(shè)置background才能消失  
		this.setOutsideTouchable(false);
        
      //自定義動(dòng)畫(huà)  
      this.setAnimationStyle(R.style.PopupAnimation);
      //使用系統(tǒng)動(dòng)畫(huà)  
//      mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);  
      this.update();  
      this.setTouchable(true);
      this.setFocusable(false);
      
      GridView gridView=(GridView)view.findViewById(R.id.gridView);
      
      adapter=new GridViewAdapter(context,balls);
      
      gridView.setAdapter(adapter);
      
      TextView tv_tips=(TextView)view.findViewById(R.id.tv_tips);
      tv_tips.setText(title);
      
      btn_ok=(Button)view.findViewById(R.id.btn_ok);
      btn_ok.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if(onOkClickListener!=null){
					onOkClickListener.onOkClick(v);
				}
				if(isShowing())
					dismiss();
			}
		});
      
	}
	
	public void setSelectedNumbers(String selectedNumbers){
		this.selectedNumbers=selectedNumbers;
		selectedNumbersArray=selectedNumbers.trim().split(split);
		adapter.notifyDataSetChanged();
		
	}
	
	class GridViewAdapter extends BaseAdapter{

		private Context context;
		private String[] balls;
    	public GridViewAdapter(Context context,String[] balls){
    		this.context=context;
    		this.balls=balls;
//    		num=numbers.trim().split(split);
    		
    	}
    	
		public int getCount() {
			// TODO Auto-generated method stub
			return balls.length;
		}

		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return balls[position];
		}

		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		public View getView(int position, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			if(convertView==null){
				convertView=LayoutInflater.from(context).inflate(R.layout.simple_grid_item_1_red, null);
			}
			CheckBox checkBox = (CheckBox)convertView.findViewById(R.id.checkBox);//
			checkBox.setText(balls[position]);
			if(selectedNumbersArray!=null&&selectedNumbersArray.length>0){
				for(int i=0;i<selectedNumbersArray.length;i++){
					if(selectedNumbersArray[i].equals(String.valueOf(position))){
						checkBox.setChecked(true);
					}
				}
			}
			
			checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
				
				public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
					// TODO Auto-generated method stub
					if(onItemCheckedListener!=null){
						onItemCheckedListener.onItemCheckedChanged(buttonView,isChecked);
					}
				}
			});
			return convertView;
		}
		
	}
	//接口
	private OnItemCheckedListener onItemCheckedListener;
	public void setOnItemCheckedListener(OnItemCheckedListener onItemCheckedListener) {
		this.onItemCheckedListener = onItemCheckedListener;
	}

	public interface OnItemCheckedListener{
		public void onItemCheckedChanged(CompoundButton buttonView, boolean isChecked);
	}
	
	private OnOkClickListener onOkClickListener;
	public void setOnOkClickListener(OnOkClickListener onOkClickListener) {
		this.onOkClickListener = onOkClickListener;
	}

	public interface OnOkClickListener{
		public void onOkClick(View v);
	}
	
}

  


用法:
    
LayoutInflater mLayoutInflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);  
        view = mLayoutInflater.inflate(R.layout.popwindow, null);  
        
		NumbersPickerPopupWindow p=new NumbersPickerPopupWindow(context,view,"選擇需要的數(shù)字","0 3 6");
		p.setSelectedNumbers("1 4 6");//動(dòng)態(tài)改變選中的值,之間用空格隔開(kāi)
		p.showAtLocation(views[0], Gravity.BOTTOM, 0, 0);
//還可以定義接口
......

  


布局文件popwindow.xml:
    
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" 
    android:background="@color/bg_blue_2"
    >

   <RelativeLayout 
        android:layout_width="fill_parent"
    	android:layout_height="wrap_content"
    	android:background="@drawable/bg_title_bar"
    	android:padding="5dip"
       >
       <TextView 
        android:id="@+id/tv_tips"
        android:layout_width="wrap_content"
    	android:layout_height="wrap_content"
    	android:text="每位至少選擇一個(gè)數(shù)字"
    	android:textColor="@color/white"
    	android:layout_centerInParent="true"
        />
        <Button 
        android:id="@+id/btn_ok"
        android:layout_width="wrap_content"
    	android:layout_height="wrap_content"
    	android:text="確定"
    	android:textColor="@color/white"
    	android:background="@drawable/bg_btn_intro"
    	android:layout_alignParentTop="true"
    	android:layout_alignParentRight="true"
        />
   </RelativeLayout>
   
  	<View 
  	    android:layout_width="fill_parent"
    	android:layout_height="1dip"
    	android:background="?android:attr/listDivider"
  	    />
  	<GridView 
  	    android:id="@+id/gridView"
  	    android:layout_width="wrap_content"
    	android:layout_height="fill_parent"
    	android:numColumns="5"
    	android:horizontalSpacing="12dip"
    	android:verticalSpacing="10dip"
    	android:paddingTop="10dip"
    	android:paddingBottom="10dip"
    	android:paddingLeft="40dip"
    	android:paddingRight="40dip"
    	android:gravity="center"
    	android:layout_gravity="center"
  	    />
</LinearLayout>

  


styles.xml中定義的動(dòng)畫(huà):
    
<style name="PopupAnimation" parent="android:Animation"  mce_bogus="1" >
        <item name="android:windowEnterAnimation">@anim/anim_in_bottom</item>
        <item name="android:windowExitAnimation">@anim/anim_out_bottom</item>
    </style>

  


2個(gè)動(dòng)畫(huà):
anim_in_bottom.xml,anim_out_bottom.xml
    
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
	<translate 
	android:fromYDelta="100%p" 
	android:toYDelta="0" 
	android:duration="200" 
	android:fillAfter="true"
	android:interpolator="@android:anim/bounce_interpolator"
	/>
</set>

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
	<translate 
	android:fromYDelta="0" 
	android:toYDelta="100%p" 
	android:duration="200"
	android:fillAfter="true"
	android:interpolator="@android:anim/bounce_interpolator"
	/>
</set>

  


simple_grid_item_1_red.xml:
    
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
  	android:layout_height="wrap_content"
    android:gravity="center"
    >
<CheckBox
    android:id="@+id/checkBox"
  	android:layout_width="wrap_content"
  	android:layout_height="wrap_content"
  	android:textColor="@color/white"
  	android:gravity="center"
  	android:button="@null"  
    android:background="@drawable/bg_checkbox_redball"
    android:checked="false"
  	/>
    
</LinearLayout>

  


bg_checkbox_redball.xml:
    <?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_checked="true" android:drawable="@drawable/red_focus" /> 
    <item android:state_checked="false" android:drawable="@drawable/red" /> 
</selector> 
  





自定義PopupWindow1


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

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

【本文對(duì)您有幫助就好】

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 久热国产精品视频 | 欧美精品一区二区三区四区 | 九九爱这里只有精品 | 中文字幕国产日韩 | 精品欧美一区二区三区久久久 | 五月天中文在线 | 激情丁香开心久久综合 | 日本欧美不卡一区二区三区在线 | 高清国产一区二区三区四区五区 | 欧美簧片| caoliushequ2017| 亚洲天堂在线播放 | 奇米在线影视 | 日韩国产欧美在线观看一区二区 | 亚洲国产精品综合久久 | 九色国产 | 欧美精品一二三区 | 亚洲国产最新 | 97婷婷狠狠成人免费视频 | 日韩黄色影视 | 成人亚洲一区 | 亚洲 欧美日韩 国产 中文 | 日日摸夜夜摸人人嗷嗷叫 | 久久精品国产一区二区三区不卡 | 国产亚洲精品久久久久久老妇小说 | 欧美成人精品久久精品 | 亚洲精品免费观看 | 黄色成年在线观看 | 日韩1区 | 国产日韩一区二区三区在线观看 | 亚洲在线观看免费视频 | 日本一区视频在线播放 | 日韩一级大毛片欧美一级 | 欧美成年黄网站色视频 | 国产精品久久久AV久久久 | 精品国产影院 | 欧美午夜视频 | 国产精品成在线观看 | 92午夜剧场| 精品无码国产一区二区日本 | 久久伊人免费视频 |