0

我有ListView一个onItemonClick听众:

    @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();        
}

当用户单击一个项目时,它应该向他显示一个AlertDialog具有自定义布局的(菜单),从单击项目的视图中获取一些详细信息并在菜单布局中更改它。我得到一个:

java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView

关于如何解决这个问题的任何建议?

4

1 回答 1

0

我认为这是因为这条线:

View menuView = getLayoutInflater().inflate(R.layout.menu_friend, (ViewGroup) getCurrentFocus());

因为您将充气视图设置为对话框的布局,所以在充气时无需添加它。尝试扩充布局文件并且不要传递任何父级ViewGroup

View menuView = getLayoutInflater().inflate(R.layout.menu_friend, null);
于 2012-06-19T15:27:11.730 回答