I have a ListView with an onItemonClick listener:
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
TextView rowName = (TextView)arg1.findViewById(R.id.list_friends_friends_tab_name);
ImageView rowProfilePicture = (ImageView) arg1.findViewById(R.id.list_profile_picture);
CharSequence userName = rowName.getText();
Drawable userProfilePicture = rowProfilePicture.getDrawable();
AlertDialog.Builder menuBuilder = new AlertDialog.Builder(this);
View menuView = getLayoutInflater().inflate(R.layout.menu_friend, (ViewGroup) getCurrentFocus());
menuBuilder.setView(menuView);
menuBuilder.setCancelable(true);
TextView name = (TextView) menuView.findViewById(R.id.menu_user_name);
ImageView profilePicture = (ImageView) menuView.findViewById(R.id.menu_profile_picture);
name.setText(userName);
profilePicture.setImageDrawable(userProfilePicture);
AlertDialog menu = menuBuilder.create();
menu.setCanceledOnTouchOutside(true);
menu.show();
}
When the user clicks an item, it supposed to show him an AlertDialog(a menu) with a custom layout, get some details from the clicked item’s view and change it in the menu layout. I’m getting a:
java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView
Any suggestions on how to solve this?
I think that happens because of this line:
because you’ll set the inflated view as the layout for the dialog there is no need to add it when you inflate it. Try to inflate the layout file and don’t pass any parent
ViewGroup: