PopWindow 总是最后显示在 ListView 中...!
PopWindow always show at last in ListView...!
我正在研究 android PopupWindow
。在此应用程序中,我创建了 1 个自定义 ListView
。现在我想在用户单击自定义 ListView
的 TextView
时显示 PopupWindow
。
我的问题是:
PopupWindow
总是最后显示 TextView
即使我点击第一个或其他 TextView
。
我该如何解决这个问题??
ListView 的 TextView。
holder.end.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int[] location = new int[2];
holder.end.getLocationOnScreen(location);
p = new Point();
p.x = location[0];
p.y = location[1];
if (p != null){
showPopup(context,p);
holder.popupText.setText(holder.end.getText().toString());
}
}
});
我的弹出窗口函数。
private void showPopup(final Activity context, Point p) {
// Inflate the popup_layout.xml
LinearLayout viewGroup = (LinearLayout)context.findViewById(R.id.layoutPopup);
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.popup_layout, viewGroup);
holder.popupText = (TextView) layout.findViewById(R.id.showPopUp);
// Creating the PopupWindow
final PopupWindow popup = new PopupWindow(context);
popup.setContentView(layout);
popup.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
popup.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
popup.setFocusable(true);
int OFFSET_X = 30;
int OFFSET_Y = 30;
popup.setBackgroundDrawable(new BitmapDrawable());
popup.showAtLocation(layout.findViewById(R.id.showPopUp), Gravity.NO_GRAVITY, p.x + OFFSET_X, p.y + OFFSET_Y);
}
Tray 使用此代码更改您的点击侦听器。应该可以。
holder.end.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int[] location = new int[2];
v.getLocationOnScreen(location);
p = new Point();
p.x = location[0];
p.y = location[1];
if (p != null){
showPopup(context,p);
holder.popupText.setText(holder.end.getText().toString());
}
}
});
我正在研究 android PopupWindow
。在此应用程序中,我创建了 1 个自定义 ListView
。现在我想在用户单击自定义 ListView
的 TextView
时显示 PopupWindow
。
我的问题是:
PopupWindow
总是最后显示 TextView
即使我点击第一个或其他 TextView
。
我该如何解决这个问题??
ListView 的 TextView。
holder.end.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int[] location = new int[2];
holder.end.getLocationOnScreen(location);
p = new Point();
p.x = location[0];
p.y = location[1];
if (p != null){
showPopup(context,p);
holder.popupText.setText(holder.end.getText().toString());
}
}
});
我的弹出窗口函数。
private void showPopup(final Activity context, Point p) {
// Inflate the popup_layout.xml
LinearLayout viewGroup = (LinearLayout)context.findViewById(R.id.layoutPopup);
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.popup_layout, viewGroup);
holder.popupText = (TextView) layout.findViewById(R.id.showPopUp);
// Creating the PopupWindow
final PopupWindow popup = new PopupWindow(context);
popup.setContentView(layout);
popup.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
popup.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
popup.setFocusable(true);
int OFFSET_X = 30;
int OFFSET_Y = 30;
popup.setBackgroundDrawable(new BitmapDrawable());
popup.showAtLocation(layout.findViewById(R.id.showPopUp), Gravity.NO_GRAVITY, p.x + OFFSET_X, p.y + OFFSET_Y);
}
Tray 使用此代码更改您的点击侦听器。应该可以。
holder.end.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int[] location = new int[2];
v.getLocationOnScreen(location);
p = new Point();
p.x = location[0];
p.y = location[1];
if (p != null){
showPopup(context,p);
holder.popupText.setText(holder.end.getText().toString());
}
}
});