Reputation: 53
I have been modifying an app, which has a listview with a lot a items. When I long pressed a item, it shows a menu with Rename, Delete and other option. This contextMenu has a title, using a string which was got from the item, like a fixed text and the item name(I contract them to be one string). All things go well.
However, when I click Rename, it shows a dialog. The dialog title is set by dialog.setTitle(), using the same string above. But when the string length is small enough, like smaller than 20, then it shows well. But if the length is too long, like above 30, then it will not show the string, just show the fixed text without the item name.
I have traced the app and find when setting title, the string is the same. but the showing is different. The only difference is the former I use ContextMenu.setHeaderTitle(), the latter I use Dialog.setTitle(). The parameter I passed are always the same.
The menu title code is as follows:
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
// TODO Auto-generated method stub
AdapterContextMenuInfo mi = (AdapterContextMenuInfo) menuInfo;
menu.add(0, CONTEXT_MENU_RENAME, 0, getString(R.string.preset_rename));
menu.add(0, CONTEXT_MENU_DELETE, 0, getString(R.string.preset_delete));
mItemId = mi.position;
// super.onCreateContextMenu(menu, v, menuInfo);
// Log.d(LOGTAG,"mItemId is :" + mItemId);
String titleName = "" + getString(R.string.station_name)+ "" +getNameFromId(mItemId);
Log.e(LOGTAG, "1. getNameFromId = " + titleName);
menu.setHeaderTitle(titleName);
}
The dialog title code is as follows:
case DIALOG_RENAME_ID:
String titleName = "" + getString(R.string.station_name)+ "" + getNameFromId(mItemId);
Log.e(LOGTAG, "2. getNameFormId " + titleName);
mRenameDialog.setTitle(titleName); // Note: here set the dialog
final EditText editText = (EditText) mRenameDialog
.findViewById(R.id.name);
editText.setText(getNameFromId(mItemId));
Button bOk = (Button) mRenameDialog.findViewById(R.id.save);
bOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String rename = editText.getText().toString();
if (TextUtils.isEmpty(rename)) {
Context context = getApplicationContext();
Toast toast = Toast.makeText(context, getString(R.string.station_name_empty),
Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0);
toast.show();
} else {
saveStationName(mItemId,rename);
mRenameDialog.dismiss();
}
}
});
Button bCancel = (Button) mRenameDialog.findViewById(R.id.cancel);
bCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mRenameDialog.dismiss();
}
});
break;
Could someone know the reason? And can someone explain it and fix it?
Upvotes: 1
Views: 714
Reputation: 11
The problem might be the setting for the dialog or ContextMenu, which was not defined by your app, but the common component setting. The title of dialog or contextmenu is a textview, which might be set by singline attribute. In this case, it might be that contextmenu doesn't set the singleLine attribute but the dialog set the singleLine attribute to true. You could check the dialog_title.xml files of source code.
Upvotes: 1