在一个活动中,我有两个文本视图。在上下文菜单中,我可以选择更改其中一个文本视图的文本大小。我试过这样的东西..
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()){
case R.id.menutextSize:
final CharSequence[] items = {"Normal","Large","Larger"};
AlertDialog.Builder builder = new
AlertDialog.Builder(this);
builder.setTitle("Select TextSize");
builder.setSingleChoiceItems(items, -1,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Toast.makeText(getApplicationContext(), items[item],
Toast.LENGTH_SHORT).show();
}
});
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
int textSize = (int)mBodyText.getTextSize();
if (items[whichButton] == "Normal")
{
mTextv.setTextSize(12);
}
if (items[whichButton] == "Large")
{
mTextv.setTextSize(14);
}
if (items[whichButton] == "Larger")
{
mTextv.setTextSize(16);
}
}
});
builder.setNegativeButton("cancel", null);
builder.show();
return true;
}
t 当我单击单选按钮时,它显示“强制关闭”消息。我该如何解决这个问题?谢谢..