2012-02-06 52 views

回答

15

請試試這個:

public class WvActivity extends Activity { 

TextView tx; 
String[] s = { "India ", "Arica", "India ", "Arica", "India ", "Arica", 
     "India ", "Arica", "India ", "Arica" }; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    final ArrayAdapter<String> adp = new ArrayAdapter<String>(WvActivity.this, 
      android.R.layout.simple_spinner_item, s); 

    tx= (TextView)findViewById(R.id.txt1); 
    final Spinner sp = new Spinner(WvActivity.this); 
    sp.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); 
    sp.setAdapter(adp); 

    AlertDialog.Builder builder = new AlertDialog.Builder(WvActivity.this); 
    builder.setView(sp); 
    builder.create().show(); 
    } 
} 
+1

讓我知道如果u需要更多 – 2012-02-06 09:35:07

+0

我可以問你一個問題:哪裏是從LayoutParams.Wrap_content?我的意思是我應該導入哪個包 – detno29 2012-02-06 10:28:35

+0

import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; – 2012-02-06 10:51:39

0

相反,爲什麼你不使用一個活動,並將其設置爲對話框樣式。應該像使用相同的視覺方法,並且可以按照自己的需要設計對話框。

+0

這個答案救了我:)日 – 2015-11-08 14:47:16