private void initPopWindow(final TextView tview) {
final String[] name = { "份", "斤", "个", "人", "桌", "只", "半份", "小份", "大份",
"两", "半只", "锅", "碗", "壶", "打", "瓶", "杯", "听", "罐", "例", "套",
"串" };
View contentView = LayoutInflater.from(getActivity()).inflate(
R.layout.popwindow, null);
contentView.setBackgroundColor(Color.WHITE);
popupWindow = new PopupWindow(findViewById(R.id.fl_layout), 159, 250);
popupWindow.setContentView(contentView);
TextView textView = (TextView) contentView.findViewById(R.id.text);
textView.setText("单位");
ListView listView = (ListView) contentView.findViewById(R.id.list);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1, name);
listView.setAdapter(adapter);
popupWindow.setBackgroundDrawable(new PaintDrawable());
popupWindow.setFocusable(true);
popupWindow.setOutsideTouchable(true);
popupWindow.showAsDropDown(tview);
popupWindow.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss() {
mUp.setImageDrawable(getActivity().getResources().getDrawable(
R.drawable.sdj));
}
});
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
mUp.setImageDrawable(getActivity().getResources().getDrawable(
R.drawable.puj));
popupWindow.dismiss();
tview.setText(name[position]);
}
});
}
PopWindow的使用方法之一
最新推荐文章于 2024-05-13 14:12:16 发布