2011-04-28 111 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