안 드 로 이 드 프로 그래 밍 은 가짜 미 단 이나 타 오 바 오의 다단 계 분류 메뉴 효과 예제[데모 소스 다운로드 첨부]를 실현 합 니 다.

4165 단어 Android메뉴
이 사례 는 안 드 로 이 드 프로 그래 밍 이 가짜 미 단 이나 타 오 바 오의 다단 계 분류 메뉴 효 과 를 실현 하 는 것 을 보 여 준다.여러분 께 참고 하도록 공유 하 겠 습 니 다.구체 적 으로 는 다음 과 같 습 니 다.
여기 서 실현 해 야 할 것 은 미 단/타 오 바 오/바 이 두 찹쌀 다단 계 분류 메뉴 효과 이다.분류 수량 이 매우 많 을 때 2 급 분 류 를 고려 할 수 있 는데,예 를 들 어 미 단 과 같은 표현 방식 은 좋 은 선택 이다.
우선 위의 효과 그림:
 
주 코드:
1.PopupWindow 초기 화 과정:

popupWindow = new PopupWindow(this);
View view = LayoutInflater.from(this).inflate(R.layout.popup_layout, null);
leftLV = (ListView) view.findViewById(R.id.pop_listview_left);
rightLV = (ListView) view.findViewById(R.id.pop_listview_right);
popupWindow.setContentView(view);
popupWindow.setBackgroundDrawable(new PaintDrawable());
popupWindow.setFocusable(true);
popupWindow.setHeight(ScreenUtils.getScreenH(this) * 2 / 3);
popupWindow.setWidth(ScreenUtils.getScreenW(this));
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
  @Override
  public void onDismiss() {
    darkView.startAnimation(animOut);
    darkView.setVisibility(View.GONE);
    leftLV.setSelection(0);
    rightLV.setSelection(0);
  }
});

2.왼쪽 메뉴 클릭 이벤트:

//  ListView    
leftLV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  @Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    //    
    List<SecondClassItem> list2 = firstList.get(position).getSecondList();
    //       ,     
    if (list2 == null || list2.size() == 0) {
      popupWindow.dismiss();
      int firstId = firstList.get(position).getId();
      String selectedName = firstList.get(position).getName();
      handleResult(firstId, -1, selectedName);
      return;
    }
    FirstClassAdapter adapter = (FirstClassAdapter) (parent.getAdapter());
    //            item,        
    if (adapter.getSelectedPosition() == position){
      return;
    }
    //            ,     
    adapter.setSelectedPosition(position);
    adapter.notifyDataSetChanged();
    //        
    updateSecondListView(list2, secondAdapter);
  }
});

3.오른쪽 메뉴 클릭 이벤트:

//  ListView    
rightLV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  @Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    //  popupWindow,         
    popupWindow.dismiss();
    int firstPosition = firstAdapter.getSelectedPosition();
    int firstId = firstList.get(firstPosition).getId();
    int secondId = firstList.get(firstPosition).getSecondList().get(position).getId();
    String selectedName = firstList.get(firstPosition).getSecondList().get(position)
        .getName();
    handleResult(firstId, secondId, selectedName);
  }
});

4.상단 탭 클릭 이벤트(분류 메뉴 표시/숨 기기)

if (popupWindow.isShowing()) {
  popupWindow.dismiss();
} else {
  popupWindow.showAsDropDown(findViewById(R.id.main_div_line));
  popupWindow.setAnimationStyle(-1);
  //    
  darkView.startAnimation(animIn);
  darkView.setVisibility(View.VISIBLE);
}

5.왼쪽 클릭 에 따라 오른쪽 ListView 새로 고침

//    ListView
private void updateSecondListView(List<SecondClassItem> list2,
    SecondClassAdapter secondAdapter) {
    secondList.clear();
    secondList.addAll(list2);
    secondAdapter.notifyDataSetChanged();
}

전체 인 스 턴 스 코드 는 여 기 를 클릭 하 십시오본 사이트 다운로드
더 많은 안 드 로 이 드 관련 내용 에 관심 이 있 는 독자 들 은 본 사이트 의 주 제 를 볼 수 있다.,,,,,,,
본 고 에서 말 한 것 이 여러분 의 안 드 로 이 드 프로 그래 밍 에 도움 이 되 기 를 바 랍 니 다.

좋은 웹페이지 즐겨찾기