2013-02-27 89 views
0

我正在開發一個Android應用程序。在其中一項活動中,我列出了一系列服務,並希望用戶對每項服務進行評分。這些服務位於TableLayout(每個服務在其自己的行中)。在行的末尾,我有一個費率button。當用戶點擊它時,Dialog彈出ratingBar,EditView和底部的兩個按鈕。我的問題是,當鍵盤彈出按鈕,並且用戶在EditText框中寫入幾行時,關鍵字隱藏按鈕。因此,用戶不能按下按鈕,用戶需要最小化鍵盤才能看到按鈕。填寫屏幕時對話框不可滾動

現在,我看到了幾個關於該主題的問題,但他們都有xml解決方案。在我的情況下,對話框都是代碼,在這種情況下我不使用xml佈局。 (我不知道這是正確的方式,但它適合我的需要)

這裏是一個圖片 Here is the example of what happens

這是對話框的代碼。點擊費率按鈕時會出現這種情況。 有什麼建議嗎?

 e.setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       boolean same = false; 
       TableRow row = new TableRow(QAListActivity.this); 
       RatingBar ratingBar = new RatingBar(QAListActivity.this);; 
       Dialog rankDialog = new Dialog(QAListActivity.this); 

       rankDialog.setContentView(R.layout.qa_rate); 
       rankDialog.setCancelable(true); 
       rankDialog.setCanceledOnTouchOutside(true); 


       TableLayout table1 = new TableLayout(QAListActivity.this); 
       ArrayList<RatingBar> ratingBars = new ArrayList<RatingBar>(); 
       EditText comment = new EditText(QAListActivity.this); 

       for(int z = 0; z < tour.QAList.size(); z++){ 
        if(tour.QAList.get(z).getServiceType().equalsIgnoreCase(tour.voucherList.get(position).getServiceType())){ 
         rankDialog.setTitle("Rate " + tour.voucherList.get(position).getDescription()); 
         same = true; 
         row = new TableRow(QAListActivity.this); 
         TextView text = new TextView(QAListActivity.this); 
         ratingBar = new RatingBar(QAListActivity.this); 
         ratingBars.add(ratingBar); 
         text.setText(tour.QAList.get(z).getQualityDesc()); 
         text.setTextSize(20); 
         text.setHeight(40); 
         text.setGravity(Gravity.CENTER_VERTICAL); 

         row.addView(text); 
         row.addView(ratingBar); 
         row.setGravity(Gravity.CENTER); 
         table1.addView(row,new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); 
         tour.voucherList.get(position).voucher_rating.add(tour.QAList.get(z)); 
        } 
       } 

       if(same){ 

        String type = tour.voucherList.get(position).getServiceType(); 

        if (type.equalsIgnoreCase("CNV")){ 

         String[] qa_bus = {"Bus Make","Bus Year","Number of Seats","Bus Company","Bathroom on Bus?","Driver's Name", 
           "Driver speaks English","Helpfulness of driver (on/off bus)","Were there Gate1 signs on the bus?"}; 
         TableLayout table_bus = new TableLayout(QAListActivity.this); 

         for(int count = 0; count < qa_bus.length; count++){ 
          TableRow row_make = new TableRow(QAListActivity.this); 
          EditText make = new EditText(QAListActivity.this); 
          make.setHint(qa_bus[count]); 
          make.setWidth(table.getWidth()/2+50); 
          row_make.addView(make); 
          row_make.setGravity(Gravity.CENTER); 
          table_bus.addView(row_make, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.FILL_PARENT)); 
         } 
         table1.addView(table_bus);  
        } 
        else{ 
         TableLayout table_comment = new TableLayout(QAListActivity.this); 
         TableRow row_comment = new TableRow(QAListActivity.this); 
         comment = new EditText(QAListActivity.this); 

         comment.setHint("Remarks"); 
         comment.setWidth(table.getWidth()/2+50); 

         row_comment.addView(comment); 
         row_comment.setGravity(Gravity.CENTER); 
         table_comment.addView(row_comment, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.FILL_PARENT)); 
         table1.addView(table_comment);  
        } 

        TableLayout table_buttons = new TableLayout(QAListActivity.this); 
        TableRow save_row = new TableRow(QAListActivity.this); 
        Button save = new Button(QAListActivity.this); 
        save.setText("Save"); 
        save_row.addView(save);  
        save_row.setGravity(Gravity.CENTER); 

        final Dialog rankDialogTemp = rankDialog; 
        final ArrayList<RatingBar> ratingBarsTemp = ratingBars; 
        final EditText remarksTemp = comment; 
        save.setOnClickListener(new View.OnClickListener() { 

         public void onClick(View v) { 
          for(int xx = 0; xx < ratingBarsTemp.size(); xx++){ 
           Log.d("ratingBar", "" + ratingBarsTemp.get(xx).getRating()); 
           tour.voucherList.get(position).voucher_rating.get(xx).setRating(ratingBarsTemp.get(xx).getRating()); 
          } 
          tour.voucherList.get(position).setQAcompleted(true); 
          tour.voucherList.get(position).setRemarks(remarksTemp.getText().toString()); 
          rowTemp.setBackgroundColor(Color.GREEN); 
          getInfo.saveOfflineData(QAListActivity.this, new Gson().toJson(TourListActivity.TourList), DateFormat.getDateTimeInstance().format(new Date())); 
          rankDialogTemp.dismiss(); 
         } 
        }); 

        Button back = new Button(QAListActivity.this); 
        back.setText("Back"); 
        save_row.addView(back);  
        back.setOnClickListener(new View.OnClickListener() { 
         public void onClick(View v) { 
          rankDialogTemp.dismiss(); 
         } 
        });        
        table_buttons.addView(save_row); 
        table1.addView(table_buttons); 

       } 
       rankDialog.addContentView(table1, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 

       //now that the dialog is set up, it's time to show it  
       rankDialog.show();     
      } 
     }); 

qa_rate.xml代碼:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/qa_rate" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" > 
    <TableLayout 
     android:id="@+id/rating" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:paddingLeft="5dp" 
     android:stretchColumns="*" 
     android:paddingRight="5dp" 
     android:orientation="vertical" > 


    </TableLayout > 
    </ScrollView> 
+0

您應該定義一個佈局,將所有內容放入['ScrollView'](http://developer.android.com/reference/android/widget/ScrollView.html)。然後在運行時將佈局膨脹到對話框。 – 2013-02-27 03:32:20

+0

你可以添加你的xml佈局 – NaviRamyle 2013-02-27 03:53:15

+0

我加了我的代碼 – Mike 2013-02-27 13:55:24

回答

0

也許與windowSoftInputMode

http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft

發揮或許把你的按鈕滾動視圖,使用戶可以向下滾動到它。

+0

但按鈕是對話框中表格的一部分。這些按鈕位於表格的最後一行。 – Mike 2013-02-27 03:04:42

+0

將整個表格放在滾動視圖中。如果您不想定義xml佈局,可以動態執行此操作。儘管我強烈建議您切換到xml佈局,但它們更易於使用。你能告訴我你的代碼嗎?你在哪裏添加表格到視圖中? – nedaRM 2013-02-27 04:08:41

+0

你看到了代碼嗎?任何人?該對話框已經在scrollview中 – Mike 2013-03-02 23:33:46