2012-04-20 21 views
1

ListPopupWindowの幅と高さを不運に設定しようとしています。私はLayatParamsについて読んでいますが、ListPopupWindowのsetLayoutParamsはありません。これらのパラメータはどのように設定するのですか?ListPopupWindow:setWidth、setHeightは効果がありません

ListPopupWindow lpw = new ListPopupWindow(TestActivity.this); 
CustomAdapter stringAdapter = new CustomAdapter(TestActivity.this, R.layout.row,strings); 
lpw.setAdapter(stringAdapter); 
lpw.setAnchorView(v); 
lpw.setWidth(150); 
lpw.setHeight(300); 
lpw.show(); 

ここで、vはボタンです。

+0

アダプターの内部には何かがありますか? –

+0

文字列のリストがアダプターにあります。 – benkdev

答えて

4

以下のコードは私にとって非常にうまく動作しています。

String[] listItems = {"item 1", "item 2 ", "list", "android", "item 3", "foobar", "bar", }; 
@SuppressWarnings({ "unchecked", "rawtypes" }) 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    Button btn=(Button)findViewById(R.id.btnwillappear); 
    btn.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      ListPopupWindow lpw = new ListPopupWindow(Test_listpopActivity.this); 
      lpw.setAdapter(new ArrayAdapter(Test_listpopActivity.this, android.R.layout.simple_list_item_1, listItems)); 
      lpw.setAnchorView(findViewById(R.id.txtwillappear)); 
      lpw.setWidth(150); 
      lpw.setHeight(300); 
      lpw.show(); 

     } 
    }); 

} 

2つの可能性の問題があります。最初はアダプタ、もう1つはコードが実行されている場所です。後者の場合は、コードがonCreateにないことを確認してください。

+0

アダプターに問題がある可能性がありますか? – IARI

関連する問題