2011-04-28 151 views
0
public Dialog onCreateDialog(int id){ 
     AlertDialog.Builder builder=new AlertDialog.Builder(this); 

     builder.setTitle("PubQuiz"); 


      TextView player = new TextView(this); 
      player.setText("Player1"); 
      builder.setView(player); 

      TextView team = new TextView(this); 
      team.setText("TeamA"); 
      builder.setView(team); 


     return builder.create(); 

     } 

如何獲得第二個textview顯示?對話框問題

回答

0
public Dialog onCreateDialog(int id) { 
    AlertDialog.Builder builder=new AlertDialog.Builder(this); 

    builder.setTitle("PubQuiz"); 

    LinearLayout lay = new LinearLayout(context); 
    lay.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); 
    lay.setOrientation(LinearLayout.VERTICAL); 
    TextView player = new TextView(this); 
    player.setText("Player1"); 
    lay.addView(player); 

    TextView team = new TextView(this); 
    team.setText("TeamA"); 
    lay.addView(team); 

    builder.setView(lay); 

    return builder.create(); 
} 

試試這個

+0

謝謝:)什麼情況下該線路上的意思的LinearLayout奠定=新的LinearLayout(背景); – OoviperoO 2011-04-28 13:01:59

+0

你可以寫Activityname.this – Dharmendra 2011-04-28 13:09:41

+0

如果我加這樣\t Button twopoints = new Button(this); \t twopoints.setText(「2 points」); \t lay.addView(twopoints);如何在該代碼塊上添加actionlistener – OoviperoO 2011-04-28 14:13:38