내 listView 요소 안에있는 버튼에 onClickListener가 있습니다.이 요소는 자체에서 팝업을 표시해야합니다.ListView에서 요소의 정확한 y 위치
나는 그것을 달성하기 위해 노력한 방법은 단순히 v.getBottom()
을 onClickListener 안에 사용하는 것이 었습니다. 그러나 이렇게하면 클릭 한 버튼의 정확한 위치가 반환되지 않습니다. https://stackoverflow.com/a/10808454/3963566
View c = listView.getChildAt(0);
int yPosition = (int) listView.getChildAt(position).getBottom() - (-c.getTop() + listView.getFirstVisiblePosition() * c.getHeight());
popupWindow.showAtLocation(listView, Gravity.CENTER, 0, yPosition);
어댑터 코드 :
난 후 정확한 스크롤 위치를 얻기 위해이 답변을 사용되는 listItem의 yPosition을 계산하여 위치를 얻기 위해 노력@Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(R.layout.search_result, parent, false);
listView = (ListView) parent;
mainContainer = (LinearLayout) parent.getParent().getParent().getParent();
ibEmployment = (SquareImageButton) rowView.findViewById(R.id.ib_employment);
ibEmployment.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showEmploymentPopup(v, position);
}
});
}
private void showEmploymentPopup(View v, int position) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.popup_categories,null);
PopupWindow pw = new PopupWindow(layout, 400, 600, true);
// display the popup in the center
pw.showAtLocation(v, Gravity.TOP, 0, v.getTop() + v.getMeasuredHeight() + 300);
initializeCategoriesList(position);
setCertificateStatus(position);
pw.showAsDropDown(v);
}
을하지만 yPosition입니다 목록이 스크롤되지 않는 한 처음 두 목록 항목에 대해서만 정확합니다.
showAtLocation 메서드 내에서 listview 대신 childview를 전달하여 팝업을 표시하려고 했습니까? –
@MohamedMohaideenAH 예. 팝업은 항상 listView – Max90
의 맨 위에 표시됩니다. 내 대답을 확인하십시오. –