package xmu.zgy;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.SimpleAdapter;
/**
*
* @author yulongfei
* @blog blog.csdn.net/zgyulongfei
*
*/
public class PopupWindowDemoActivity extends Activity {
private Button button;
private PopupWindow popupWindow;
private ListView listView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initControls();
}
private void initControls() {
LayoutInflater inflater = LayoutInflater.from(this);
View view = inflater.inflate(R.layout.listview_demo, null);
SimpleAdapter adapter = new SimpleAdapter(this, getData(),
R.layout.item,
new String[] { "text" },
new int[] { R.id.item });
listView = (ListView) view.findViewById(R.id.listview);
listView.setAdapter(adapter);
popupWindow = new PopupWindow(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
popupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg));
popupWindow.setOutsideTouchable(true);
popupWindow.setAnimationStyle(android.R.style.Animation_Dialog);
popupWindow.update();
popupWindow.setTouchable(true);
popupWindow.setFocusable(true);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!popupWindow.isShowing()) {
popupWindow.showAsDropDown(button, 0, 0);
}
}
});
}
private List<Map<String, String>> getData() {
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
Map<String, String> map = new HashMap<String, String>();
map.put("text", "中国");
list.add(map);
map = new HashMap<String, String>();
map.put("text", "加油");
list.add(map);
map = new HashMap<String, String>();
map.put("text", "钓鱼岛是中国的");
list.add(map);
map = new HashMap<String, String>();
map.put("text", "!!");
list.add(map);
return list;
}
}
popupwindow中显示listview自适配
5星 · 超过95%的资源 需积分: 9 50 浏览量
2012-09-12
23:31:29
上传
评论 1
收藏 48KB RAR 举报
似乎已不再年轻
- 粉丝: 542
- 资源: 11
最新资源
- 基于Python实现的自动化办公项目.zip
- 基于python实现的基于PyQt5和爬虫的小说阅读系统.zip
- 机械设计整经机上纱自动化sw20非常好的设计图纸100%好用.zip
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈