Android 从ListView弹出窗口';s setOnItemClickListener未显示
我试图从ListView的setOnItemClickListener显示PopupWindow,但什么也没有显示 我做错了什么 谢谢 HomeActivity.java base.xmlAndroid 从ListView弹出窗口';s setOnItemClickListener未显示,android,popupwindow,Android,Popupwindow,我试图从ListView的setOnItemClickListener显示PopupWindow,但什么也没有显示 我做错了什么 谢谢 HomeActivity.java base.xml 当我使用 layout = new LinearLayout(HomeActivity.this); /* ... */ popUp = new PopupWindow(layout,LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT); popUp.show
当我使用
layout = new LinearLayout(HomeActivity.this);
/* ... */
popUp = new PopupWindow(layout,LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
popUp.showAtLocation(findViewById(R.id.base), Gravity.CENTER, 500, 500);
而不是
popUp = new PopupWindow(HomeActivity.this);
layout = new LinearLayout(HomeActivity.this);
/* ... */
popUp.setContentView(layout);
popUp.showAtLocation(findViewById(R.id.base_layout), Gravity.CENTER, 500, 500);
当我使用
layout = new LinearLayout(HomeActivity.this);
/* ... */
popUp = new PopupWindow(layout,LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
popUp.showAtLocation(findViewById(R.id.base), Gravity.CENTER, 500, 500);
而不是
popUp = new PopupWindow(HomeActivity.this);
layout = new LinearLayout(HomeActivity.this);
/* ... */
popUp.setContentView(layout);
popUp.showAtLocation(findViewById(R.id.base_layout), Gravity.CENTER, 500, 500);
使用以下命令:
//popAwindow
private void popAwindow(View parent) {
if (window == null) {
LayoutInflater lay = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = lay.inflate(R.layout.popupwindow, null);
v.setBackgroundDrawable(getResources().getDrawable(R.drawable.rounded_corners_view));
cancel = (Button) v.findViewById(R.id.cancel);
cancel.setOnClickListener(cancelListener);
window = new PopupWindow(v, 500,260);
}
window.setBackgroundDrawable(getResources().getDrawable(R.drawable.rounded_corners_pop));
window.setFocusable(true);
window.update();
window.showAtLocation(parent, Gravity.CENTER_VERTICAL, 0, 0);
}
OnClickListener cancelListener=new OnClickListener(){
@Override
public void onClick(View v){
closeWindow();
}
};
//for cloasing popupwindow"
private void closeWindow(){
if (window != null) {
window.dismiss();
}
}
// call on list item click :
@Override
public void onItemClick(AdapterView<?> a, View v, int position, long id){
popAwindow(v);//your popupwindow
}
//popAwindow
私有void popAwindow(查看父对象){
如果(窗口==null){
LayoutInflater lay=(LayoutInflater)getSystemService(Context.LAYOUT\u INFLATER\u SERVICE);
视图v=布局充气(R.layout.popupwindow,空);
v、 setBackgroundDrawable(getResources().getDrawable(R.drawable.rounded_corners_view));
cancel=(按钮)v.findviewbyd(R.id.cancel);
cancel.setOnClickListener(cancelListener);
窗口=新的弹出窗口(v,500260);
}
setBackgroundDrawable(getResources().getDrawable(R.drawable.rounded_-corners_-pop));
window.setFocusable(true);
window.update();
window.showAtLocation(父级,重心垂直,0,0);
}
OnClickListener cancelListener=新的OnClickListener(){
@凌驾
公共void onClick(视图v){
关闭窗口();
}
};
//用于关闭popupwindow“
私有void closeWindow(){
如果(窗口!=null){
window.disclose();
}
}
//调用列表项单击:
@凌驾
public void onItemClick(适配器视图a、视图v、内部位置、长id){
popAwindow(v);//你的popAwindow
}
使用以下方法:
//popAwindow
private void popAwindow(View parent) {
if (window == null) {
LayoutInflater lay = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = lay.inflate(R.layout.popupwindow, null);
v.setBackgroundDrawable(getResources().getDrawable(R.drawable.rounded_corners_view));
cancel = (Button) v.findViewById(R.id.cancel);
cancel.setOnClickListener(cancelListener);
window = new PopupWindow(v, 500,260);
}
window.setBackgroundDrawable(getResources().getDrawable(R.drawable.rounded_corners_pop));
window.setFocusable(true);
window.update();
window.showAtLocation(parent, Gravity.CENTER_VERTICAL, 0, 0);
}
OnClickListener cancelListener=new OnClickListener(){
@Override
public void onClick(View v){
closeWindow();
}
};
//for cloasing popupwindow"
private void closeWindow(){
if (window != null) {
window.dismiss();
}
}
// call on list item click :
@Override
public void onItemClick(AdapterView<?> a, View v, int position, long id){
popAwindow(v);//your popupwindow
}
//popAwindow
私有void popAwindow(查看父对象){
如果(窗口==null){
LayoutInflater lay=(LayoutInflater)getSystemService(Context.LAYOUT\u INFLATER\u SERVICE);
视图v=布局充气(R.layout.popupwindow,空);
v、 setBackgroundDrawable(getResources().getDrawable(R.drawable.rounded_corners_view));
cancel=(按钮)v.findviewbyd(R.id.cancel);
cancel.setOnClickListener(cancelListener);
窗口=新的弹出窗口(v,500260);
}
setBackgroundDrawable(getResources().getDrawable(R.drawable.rounded_-corners_-pop));
window.setFocusable(true);
window.update();
window.showAtLocation(父级,重心垂直,0,0);
}
OnClickListener cancelListener=新的OnClickListener(){
@凌驾
公共void onClick(视图v){
关闭窗口();
}
};
//用于关闭popupwindow“
私有void closeWindow(){
如果(窗口!=null){
window.disclose();
}
}
//调用列表项单击:
@凌驾
public void onItemClick(适配器视图a、视图v、内部位置、长id){
popAwindow(v);//你的popAwindow
}