我想在popup
窗口中添加一个标题,该标题应该在弹出列表中修复。只有弹出列表应为scroll
。我怎样才能做到这一点?请建议我。
public PopupWindow popupWindowcountry() {
PopupWindow popupWindow = new PopupWindow(this);
ListView listView = new ListView(this);
listView.setAdapter(Country_Padpter);
popupWindow.setFocusable(true);
popupWindow.setWidth((int) (getWindowManager().getDefaultDisplay()
.getWidth() / 2.2));
popupWindow.setHeight(515);
popupWindow.setContentView(listView);
return popupWindow;
}
private class PopupWindows_Adpter extends BaseAdapter {
@Override
public int getCount() {
return Country_arrayList.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@SuppressWarnings("unused")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// View grid;
LayoutInflater inflater = (LayoutInflater) DNPActivity.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = null;
if (convertView == null) {
convertView = new View(DNPActivity.this);
convertView = inflater
.inflate(R.layout.country_popup_row, null);
final TextView textView = (TextView) convertView
.findViewById(R.id.item_txt_popup_row);
final LinearLayout layout = (LinearLayout) convertView
.findViewById(R.id.popup_ll);
// final TextView header=(TextView)
// convertView.findViewById(R.id.item_txt_popup_header);
textView.setText(Country_arrayList.get(position).getName());
textView.setBackgroundColor(Color.WHITE);
textView.setTextColor(Color.BLACK);
textView.setTextSize(18);
textView.setPadding(15, 10, 10, 10);
layout.setOnClickListener(new OnClickListener() {
@SuppressLint("ShowToast")
@Override
public void onClick(View v) {
String selectedtext = textView.getText().toString();
Toast.makeText(DNPActivity.this, selectedtext,
Toast.LENGTH_LONG).show();
country_selected_txt = selectedtext;
tvtotalnewspapernumber.setText(country_selected_txt);
popupWindowcountry.dismiss();
new FilterAsync().execute();
}
});
} else {
convertView = (View) convertView;
}
return convertView;
}
}
答案 0 :(得分:1)
ListPopupWindow从API 11开始有几次调用。
void setPromptView(View prompt)
void setPromptPosition(int position)
这些将在列表视图的上方或下方添加自定义视图,但不能同时添加两者。列表视图滚动不会影响视图。
答案 1 :(得分:0)
在弹出窗口中添加一个标题,该标题应该在弹出列表中修复
您可以通过在PopUpWindow中添加ListView for ListView来实现相同功能。这样做:
TextView tv = new TextView(this);
tv.setText("your title text here");
listView.addHeaderView(tv);
或者您也可以使用HeaderView的自定义布局,请参阅以下教程: