2012-06-19 66 views
0

我有一個onItemonClick聽者ListView異常與一個ListView OnItemClickListener

@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 

有關如何解決這個問題的任何建議?

回答

0

我認爲,是因爲這行:

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

,因爲你設置的充氣視圖的佈局的對話框,沒有必要添加它,當你它充氣。嘗試膨脹佈局文件並且不通過任何父代ViewGroup

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