2015-07-06 84 views
0

我想在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

使用'addHeaderView'爲ListView添加標題 –

回答

0

添加在彈出的窗口的標題應固定在彈出的列表中

可以achive通過添加標題爲ListView控件是內部PopUpWindow相同。做到這一點的:

TextView tv = new TextView(this); 
tv.setText("your title text here"); 
listView.addHeaderView(tv); 

或者你也可以使用自定義佈局HeaderView看看下面的教程:

Listview with header footer view android

+0

我已經使用了這個...但該文本也在ListView中滾動。而我需要修復它。只有彈出列表應該滾動而不是文本標題。 –

1

ListPopupWindow具有API 11起一對夫婦的電話。

void setPromptView(View prompt) 
void setPromptPosition(int position) 

這些將在列表視圖的上方或下方添加自定義視圖,但不能同時添加。該視圖不會受到列表視圖滾動的影響。

相關問題