码迷,mamicode.com
首页 > Windows程序 > 详细

Popupwindow

时间:2015-10-21 10:40:50      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:

简单的里面调用iniPopupWindow();

if (pwMyPopWindow.isShowing()) {

pwMyPopWindow.dismiss();// 关闭
} else {

pwMyPopWindow.showAsDropDown(searchView);// 显示
}
//popupwindow代码
/*
private void iniPopupWindow() {

LayoutInflater inflater = (LayoutInflater) this
.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.popup_listviewhuanbao, null);
pwMyPopWindow = new PopupWindow(layout);
pwMyPopWindow.setFocusable(true);// 加上这个popupwindow中的ListView才可以接收点击事件


// 控制popupwindow的宽度和高度自适应
pwMyPopWindow.setWidth(500);
pwMyPopWindow.setHeight((500)
* NUM_OF_VISIBLE_LIST_ROWS);

// 控制popupwindow点击屏幕其他地方消失
pwMyPopWindow.setBackgroundDrawable(this.getResources().getDrawable(
R.drawable.grid_selector_background_focus));// 设置背景图片,不能在布局中设置,要通过代码来设置
pwMyPopWindow.setOutsideTouchable(true);// 触摸popupwindow外部,popupwindow消失。这个要求你的popupwindow要有背景图片才可以成功,如上
}
*/
/*

街景动作
*//*

public void hideSmallStreet(){
if(mStreetSmallLayout !=null){
mStreetSmallLayout.setVisibility(View.INVISIBLE);
}

}
public void showSmallStreet(){

if(mStreetSmallLayout !=null){
mStreetSmallLayout.setVisibility(View.VISIBLE);
}
}
public void setSmallStreetText(String text){
mStreetTextView.setText(text);
}
public void setSmallStreetImage(Bitmap bm){
mStreetSmallImage.setImageBitmap(bm);
}
*/
//封装好的类
  v.setSelected(!v.isSelected());
if (!isLayerSelectPopupShow) {
if (myPopupWindowManager2 == null) {
myPopupWindowManager2 = new MyPopupWindowManager2(LeaderMapActivity.this, R.layout.popup_listviewhuanbao, 0, 0);
}
myPopupWindowManager2.setOutsideTouchable(true);
myPopupWindowManager2.showStatusPopup(relativeLayout, relativeLayout.getWidth(), relativeLayout.getHeight());
类代码
package com.huitian.egis;

import android.content.Context;
import android.content.Intent;
import android.graphics.Point;
import android.os.AsyncTask;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.PopupWindow;
import android.widget.SimpleAdapter;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
import android.widget.TextView;
import android.widget.Toast;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Created by huitian_macmini on 15/8/4.
*/
public class MyPopupWindowManager2 {
private PopupWindow mPopupWindow;
private View mAncher;
private Context mContext;
private View mWindowView;
private boolean isLayerSelectPopupShow;
//popup的偏移值
private int OFFSET_X = 0;
private int OFFSET_Y = 0;

public MyPopupWindowManager2(Context context, int layoutID, int offset_x, int offset_y)
{
mContext = context;
mPopupWindow = new PopupWindow(mContext);
mPopupWindow.setFocusable(true);

mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
mAncher.setSelected(false);

}
});

OFFSET_X = offset_x;
OFFSET_Y = offset_y;

LayoutInflater layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mWindowView = layoutInflater.inflate(layoutID, null);
mWindowView.setBackgroundResource(R.color.popup2);

final Spinner spinner = (Spinner)mWindowView.findViewById(R.id.spinner);
new AsyncTask<Void,Void,String>(){

@Override
protected String doInBackground(Void... params) {
try {
InputStream in=new URL("http://dc-web.gdepb.gov.cn/swryrd/pollutionsource.mvc/GetAllByHashtableEnterpriseSize").openStream();
BufferedReader reader=new BufferedReader(new InputStreamReader(in,"utf-8"));
StringBuffer content=new StringBuffer();
String line=null;
while ((line=reader.readLine())!=null){
content.append(line);
}
reader.close();
return content.toString();
} catch (IOException e) {
e.printStackTrace();
};
return null;
}

@Override
public void onPostExecute(String s) {
super.onPostExecute(s);

if(s!=null){
//textView.setText(s);

try {
JSONObject jo=new JSONObject(s);
JSONArray jsonArray = jo.getJSONArray("data");
List<String> listems = new ArrayList<String>();
for (int i=0;i<jsonArray.length();i++)
{

JSONObject jsonObjectSon= (JSONObject)jsonArray.opt(i);
String json1=jsonObjectSon.getString("SizeName");
listems.add(json1);
// str=str+jsonObjectSon.getString("zhengshu")+""+jsonObjectSon.getString("date");
}

ArrayAdapter adapter = new ArrayAdapter<String>(mContext,android.R.layout.simple_spinner_item,listems);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
AutoCompleteTextView mEndPointText = (AutoCompleteTextView) mWindowView.findViewById(R.id.EndPoint_Search);//66


/* list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

ViewGroup group= (ViewGroup) parent.getChildAt(position);
TextView text= (TextView) group.getChildAt(0);
// String s=textView.getText().toString();
Toast.makeText(Activity3.this, text.getText().toString(), Toast.LENGTH_SHORT).show();
Intent intent=new Intent();
intent.putExtra("xinxi", text.getText().toString());
intent.setClass(Activity3.this, LeaderMapActivity.class);
startActivity(intent);
}
});
*/
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}.execute();

}
public void showStatusPopup(View anchorView,int width,int height) {

int[] location = new int[2];
anchorView.getLocationOnScreen(location);
//anchorView
mAncher = anchorView;
mPopupWindow.setWidth(width - 0);
mPopupWindow.setHeight(height - 0);
Point point = new Point(location[0]+anchorView.getWidth() - mPopupWindow.getWidth() ,location[1]+ anchorView.getHeight());

// Creating the PopupWindow

mPopupWindow.setContentView(mWindowView);
// Displaying the popup at the specified location, + offsets.
mPopupWindow.showAtLocation(mWindowView, Gravity.BOTTOM, OFFSET_X,OFFSET_Y);

}

public void setOffsetX(int x)
{
OFFSET_X = x;
}

public void setOffsetY(int y)
{
OFFSET_Y = y;
}

public void setOutsideTouchable(boolean b){
mPopupWindow.setOutsideTouchable(b);
}

public void dismiss()
{

mPopupWindow.dismiss();
}
}


Popupwindow

标签:

原文地址:http://www.cnblogs.com/xiongxiaolang/p/4896980.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!