11

내 ListView가 PopupWindow 내부에 있습니다.PopupWindow의 Android Listview가 일부 장치에서 작동하지 않습니다.

내가 팝업 ASUS K00z 폰 패드 worview에서 Listup 행을 클릭하면 PopupWindow 매우 좋았을 때.

그러나 HTC Z715e에서

이 (가되지 해고 이벤트를 클릭 onitem) 작동하지 않는 것은

1.이 내 목록보기 항목 레이아웃입니다

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/ln_testpopitemcon" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="52dp" 
    android:background="#3b8ed4" 
    android:descendantFocusability="blocksDescendants"> 

<ImageView 
    android:id="@+id/img_testiconmenu" 
    android:layout_margin="10dp" 
    android:layout_width="32dp" 
    android:layout_height="32dp" 
    android:src="@drawable/radio_selected" 
    android:clickable="false" 
    android:focusable="false" 
    android:focusableInTouchMode="false"/> 

    <TextView 
     android:id="@+id/tv_testtitlemenu" 
     android:gravity="left|center_vertical" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:clickable="false" 
     android:focusable="false" 
     android:focusableInTouchMode="false"/> 

</LinearLayout> 

2.이 내 팝업 레이아웃입니다

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/ln_testpopocontainer" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ListView 
     android:paddingLeft="2dp" 
     android:paddingRight="2dp" 
     android:paddingBottom="2dp" 
     android:id="@+id/lv_testpop" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:choiceMode="singleChoice" 
     android:dividerHeight="2dp" 
     android:background="#00000000" 
     android:orientation="vertical"/> 

</LinearLayout> 

3. 이것은 나의 어댑터이다

public class testmenuadapter extends BaseAdapter{ 
    private Context context; 
    private ArrayList<MenuInfo> MenuList; 
    private LayoutInflater Layf; 

    public testmenuadapter(Context context, ArrayList<MenuInfo> menuList){ 
     this.context = context; 
     this.MenuList = menuList; 
     this.Layf = LayoutInflater.from(context); 
    } 

    @Override 
    public int getCount() { 
     return MenuList.size(); 
    } 

    @Override 
    public Object getItem(int position) { 
     return MenuList.get(position); 
    } 

    @Override 
    public long getItemId(int position) { 
     return position; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     ViewHolder holder = null; 
     if (convertView == null) { 
      holder = new ViewHolder(); 
      convertView = Layf.inflate(R.layout.testpopoitem, null); 

      holder.img_testiconmenu = (ImageView)convertView.findViewById(R.id.img_testiconmenu); 
      holder.tv_testtitlemenu = (TextView)convertView.findViewById(R.id.tv_testtitlemenu); 
      convertView.setTag(holder); 
     } 
     else 
     { 
      holder = (ViewHolder)convertView.getTag(); 
     } 

     MenuInfo info = MenuList.get(position); 

     if(info != null) { 
      if (holder.tv_testtitlemenu != null) { 
       holder.tv_testtitlemenu.setText(info.getTitle()); 
      } 
     } 

     return convertView; 
    } 

    public class ViewHolder 
    { 
     ImageView img_testiconmenu; 
     TextView tv_testtitlemenu; 
    } 
} 

4.이 내가 만드는 데 사용하는 코드와 쇼 팝업입니다

final View actionview = inflater.inflate(R.layout.testpopo, (ViewGroup)getActivity().findViewById(R.id.ln_testpopocontainer)); 
this.testpopup = new PopupWindow(actionview, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); 
this.testpopup.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); 
this.testpopup.setOutsideTouchable(false); 
this.testpopup.setAnimationStyle(R.style.Animation); 

this.testpopuplistview = (ListView)this.testpopup.getContentView().findViewById(R.id.lv_testpop); 

this.testmenupopup = new ArrayList<MenuInfo>(); 
this.testmenupopup.add(new MenuInfo("aaa", "AAA", 0, 0, false)); 
this.testmenupopup.add(new MenuInfo("bbb", "BBB", 0, 0, false)); 
this.testmenupopup.add(new MenuInfo("ccc", "CCC", 0, 0, false)); 

this.testpopadapter = new testmenuadapter(getActivity(), this.testmenupopup); 

this.testpopuplistview.setAdapter(this.testpopadapter); 
this.testpopuplistview.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
    @Override 
    public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { 
     Toast.makeText(getActivity(), ((MenuInfo)adapterView.getItemAtPosition(position)).getTitle(), Toast.LENGTH_LONG).show(); 
    } 
}); 

Button btnshowpop = (Button)findViewById(R.id.btn_showpop); 
btnshowpop.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View view) { 
     testpopup.showAtLocation(rootView, Gravity.CENTER, 0, 0); 
    } 
}); 

그것이 내가 내 문제를 해결할 수

편집 의 해결 방법.

은 시간을 낭비 죄송

this.testpopup = new PopupWindow(actionview, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true); 

this.testpopup = new PopupWindow(actionview, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); 

을 대체 내가 아주 바보입니다.

+1

(보기)에서 참조하시기 바랍니다 문제의 편집. – user2955394

+1

soo를 많이 고맙다, 나는 2 일에서 나의 머리를 긁고 있고, 마지막으로 나는 당신의 해결책을 얻었다, 그것은 굉장하다. –

+0

감사합니다.그것은 내 시간을 절약했다 – Dima

답변

1

당신은 ListView에에 대한 대신 BaseAdapterListAdapter를 사용하려면, 그리고 을 areAllItemsEnabled 및 가 ListAdapter를 구현하는 클래스에을 isItemEnabled에 대해 true를 반환 할 수 있습니다. 이 같은

뭔가 ...

class CustomListAdapter implements ListAdapter { 

    Activity callingActivity; 
    ArrayList<String> items; 

    public CustomListAdapter(Activity act, ArrayList<String> list) 
    { 
     callingActivity = act; 
     items = list; 
    } 

    @Override 
    public void registerDataSetObserver(DataSetObserver observer) { 
    } 

    @Override 
    public void unregisterDataSetObserver(DataSetObserver observer) { 
    } 

    @Override 
    public int getCount() { 
     return items.size(); 
    } 

    @Override 
    public Object getItem(int position) { 
     return items.get(position); 
    } 

    @Override 
    public long getItemId(int position) { 
     return 0; 
    } 

    @Override 
    public boolean hasStableIds() { 
     return false; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     AbsListView.LayoutParams params = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.WRAP_CONTENT); 

     LinearLayout ll = new LinearLayout(callingActivity); 
     ll.setLayoutParams(params); 
     ll.setGravity(Gravity.CENTER); 
     ll.setOrientation(LinearLayout.HORIZONTAL); 
     ll.setPadding(5, 5, 5, 5); 

     // 
     // Code for your list item here... 
     // 

     return ll; 
    } 

    @Override 
    public int getItemViewType(int position) { 
     return 0; 
    } 

    @Override 
    public int getViewTypeCount() { 
     return 1; 
    } 

    @Override 
    public boolean isEmpty() { 
     return false; 
    } 

    @Override 
    public boolean areAllItemsEnabled() { 
     return true; 
    } 

    @Override 
    public boolean isEnabled(int position) { 
     return true; 
    } 

} 

행운을 빕니다. :)

+0

이것은 나를 위해 작동하지 않습니다 –

3

팝업 메뉴 대신 컨텍스트 메뉴를 만들 수 있습니다. 이 링크 Creating Contextual Menus를 참조에서

http://developer.android.com/guide/topics/ui/menus.html#context-menu

: 상황에 맞는 메뉴를 만들기위한 은이 링크를 참조하십시오.

정렬 exanple u는 상황에 맞는 메뉴를 추가 할 수 있습니다 같은이에 ------ 처음처럼 OnClickListener를에 등록

registerForContextMenu 난 내 문제를 해결할 수 있습니다

for oncreate 
    @Override  
public void onCreateContextMenu(ContextMenu menu, View v,ContextMenu.ContextMenuInfo menuInfo) 
{ 
     menu.add(Menu.NONE, CONTEXT_MENU_UNPAIR_ITEM, Menu.NONE, "UNPAIR"); 
     menu.add(Menu.NONE, DEFAULT_DEVICE, Menu.NONE, "USE AS CGM DEVICE");   
    } 

For item selected in context menu 
@Override 
public boolean onContextItemSelected(MenuItem item) 
{ 
switch (item.getItemId()) 
{ 
case CONTEXT_MENU_UNPAIR_ITEM: 
//whatever u want 
break 
case DEFAULT_DEVICE: 
//whatever your logic accordind to u 
return(true); 
} 
return(super.onOptionsItemSelected(item)); 
}        
관련 문제