我是编程新手,所以也许这个问题很愚蠢。搜索互联网,但没有找到。如图所示,我需要这样做。在一行中,添加Label和EditText。请帮帮我。
public void onAddExpenseClick(View viev){
final String[] mChoose = getResources().getStringArray(R.array.mChoose);
final EditText input = new EditText(this);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.addExpensTitle)
.setCancelable(false)
.setView(input)
.setPositiveButton(R.string.addExpensPB, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if(input.getText().toString().equals("")) {
Toast.makeText(
getApplicationContext(),
"Enter the correct amount",
Toast.LENGTH_SHORT).show();
return;
}
Expense expense = new Expense();
expense.setType(getTag(mChoose[itemChoosed]).toLowerCase());
expense.setAmount((long)(100 * Double.valueOf(input.getText().toString())));
expense.setDateAndTime(dateValue);
try {
expense.setTripId(((TravelApp)getApplication()).getTripManager().getDefaultTripId());
//Log.d(LOG, expense.toString());
expense.setCurrencyCode(
((TravelApp)getApplication()).getCurrencyManager().getEntranceCurrency()
);
((TravelApp)getApplication()).getExpenseManager().create(expense);
tabFragment.gotoGridView();
} catch (SQLException e) {
e.printStackTrace();
}
}
})
.setNegativeButton(R.string.AdminDialogNB, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
})
.setSingleChoiceItems(mChoose, -1,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int item) {
itemChoosed = item;
}
});
builder.show();
}
答案 0 :(得分:0)
看起来你正朝着正确的方向前进。
How to implement a custom AlertDialog View
您需要创建自定义视图并确保对其进行充气。
提供良好教程的另一个链接。
http://www.mkyong.com/android/android-prompt-user-input-dialog-example/