我正在开发一款Android应用。在其中一项活动中,我有一个服务列表,我希望用户对每项服务进行评级。服务位于TableLayout
(每个服务在其自己的行中)。在行的末尾,我有一个费率button
。当用户点击它时,Dialog
会弹出ratingBar
,EditView
和底部的两个按钮。我的问题是,当键盘弹出按钮,并且用户在EditText
框中写入几行时,该关键字会隐藏按钮。因此,用户无法按下按钮,用户需要最小化键盘才能看到按钮。
现在,我看到关于该主题的几个问题,但他们都有xml
个解决方案。在我的例子中,对话框是所有代码,在这种情况下我不使用xml布局。 (我不确定这是正确的方法,但它适合我的需要)
这是一张图片
这是对话框的代码。这是单击率按钮时发生的情况。 有什么想法吗?
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 :(得分:0)
也许玩windowSoftInputMode
http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft
或者可以将您的按钮放在滚动视图中,以便用户可以向下滚动它。