안 드 로 이 드 모방 경 동 상품 속성 선별 기능

3964 단어 android상품 선별
선별 과 속성 선택 은 현재 매우 자주 사용 되 는 기능 모듈 입 니 다.거의 모든 앱 에서 사용 된다.

필터 단 추 를 누 르 면 봉 인 된 popupWindow 가 팝 업 됩 니 다.실 용적 인 방법 은 매우 간단 합 니 다.두 줄 코드 를 직접 표시 합 니 다.(물론 데이터 초기 화 제외)
여 기 는 예전 에 사 용 했 던 흐름 식 구조 와 약간 다르다.
이전에 사용 한 것 은 하나의 분류 이 고 프로젝트 에서 대량으로 실 용적 이지 않 았 다.이 선별 기능 은 데 이 터 를 제외 하고 거의 항목 에서 복사 되 었 다.
전체 popupWindow 레이아웃 은 사용자 정의 ListView 입 니 다.이 사용자 정의 listview 는 주로 listview 의 높이 를 제어 합 니 다.
데이터 가 적 으 면 자가 적응 이 고 데이터 가 많 으 면 화면의 절반 으로 높이 를 제한 합 니 다.
사용자 정의 ListView:

public class CustomHeightListView extends ListView { 
 
  private Context mContext; 
 
  public CustomHeightListView(Context context) { 
    this(context, null); 
  } 
 
  public CustomHeightListView(Context context, AttributeSet attrs) { 
    this(context, attrs, 0); 
  } 
 
  public CustomHeightListView(Context context, AttributeSet attrs, int defStyleAttr) { 
    super(context, attrs, defStyleAttr); 
    init(context); 
  } 
 
  private void init(Context context) { 
    mContext = context; 
  } 
 
  @Override 
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
    try { 
      //                 
      Display display = ((Activity) mContext).getWindowManager().getDefaultDisplay(); 
      DisplayMetrics d = new DisplayMetrics(); 
      display.getMetrics(d); 
      //                (d.heightPixels / 2,           200,             ) 
      heightMeasureSpec = MeasureSpec.makeMeasureSpec(d.heightPixels / 2 - 200, MeasureSpec.AT_MOST); 
    } catch (Exception e) { 
      e.printStackTrace(); 
    } 
    //       、  
    super.onMeasure(widthMeasureSpec, heightMeasureSpec); 
  } 
} 
ListView 의 모든 아 이 템 은 스 트림 레이아웃 입 니 다.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  android:layout_width="match_parent" 
  android:layout_height="wrap_content" 
  android:orientation="vertical"> 
 
  <TextView 
    android:id="@+id/tv_type_name" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 
 
  <com.example.zheng.flowlayoutdemo.view.SkuFlowLayout 
    android:id="@+id/layout_property" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 
   
</LinearLayout> 
전체 popupwindow 는 하나의 클래스 에 패키지 되 어 있 습 니 다.만 들 때 데이터 원본 을 전달 하면 됩 니 다.실 용적 일 때 직접 show 하면 됩 니 다.

flowPopWindow = new FlowPopWindow(MainActivity.this, dictList); 
    flowPopWindow.showAsDropDown(ivBack); 
확인 을 클릭 할 때 감청 을 직접 설정 하면 됩 니 다.

flowPopWindow.setOnConfirmClickListener(new FlowPopWindow.OnConfirmClickListener() { 
     @Override 
     public void onConfirmClick() { 
      StringBuilder sb = new StringBuilder(); 
      for (FiltrateBean fb : dictList) { 
       List<FiltrateBean.Children> cdList = fb.getChildren(); 
       for (int x = 0; x < cdList.size(); x++) { 
        FiltrateBean.Children children = cdList.get(x); 
        if (children.isSelected()) 
         sb.append(fb.getTypeName() + ":" + children.getValue() + ";"); 
       } 
      } 
      if (!TextUtils.isEmpty(sb.toString())) 
       Toast.makeText(MainActivity.this, sb.toString(), Toast.LENGTH_LONG).show(); 
     } 
    } 
클릭 하여 링크 열기 무료흐름 식 레이아웃
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기