2017-07-10 3 views
0

このコードでは、子ビューには、他の引数のインデックスに従って受信されたすべてのリスト項目がリサイクラビューのすべての子ビューは表示されますが、親タイトルに従って適切な特定のアイテムのみを表示するようにします。 just see this pic you'll understandExpandable Recyclerビューの子要素で、他の引数のインデックスに基づいてリスト内の特定の項目を表示する方法

private RecyclerView recyclerViewFaults; 
    private FaultAdapter mAdapter; 

    private TextView fault_counter; 

    final List<FaultTitle> titles = new ArrayList<>(); 
    final List<FaultDesc> des = new ArrayList<>(); 
//this for descriptions 
    Map<String, String> getdes(int keyId,int valId){ 
     String[] key = getResources().getStringArray(keyId); 
     String[] des = getResources().getStringArray(valId); 

     Map<String, String> dict = new HashMap<String,String>(); 
     for (int i=0, l=des.length; i<l; i++){ 
      dict.put(key[i],des[i]); 
     } 
     return dict; 
    } 
//this for titles 
    Map<String, String> getDict(int keyId, int valId) { 
     String[] keys = getResources().getStringArray(keyId); 
     String[] vals = getResources().getStringArray(valId); 

     Map<String, String> dict = new HashMap<String, String>(); 
     for (int i = 0, l = keys.length; i < l; i++) { 
      dict.put(keys[i], vals[i]); 
     } 
     return dict; 
    } 

    private void dataOk(String res) { 
     FaultTitle title; 
     String ss =""; 
     FaultDesc d1; /*= new FaultDesc("ghj");*/ 
     Map<String , String> dtcdes = getdes(R.array.dtc_keys,R.array.dtc_descrip); 

     Map<String, String> dtcVals = getDict(R.array.dtc_keys, R.array.dtc_values); 
     if (res != null) { 
      for (String dtcCode : res.split("\n")) { 
       d1 = new FaultDesc(dtcCode, dtcVals.get(dtcCode)); 
       des.add(d1); 
       Log.d("Trouble codes", dtcCode + " : " + dtcVals.get(dtcCode)+ ": "+ numberFaults); 
       title = new FaultTitle(dtcCode,dtcVals.get(dtcCode), des); 
       titles.add(title); 
       Log.d("TEST", titles.get(numberFaults).getFaultCode() + " -- "+ titles.get(numberFaults).getFaultTitle()); 
       numberFaults++; 
      } 

      fault_counter.setText(numberFaults+""); 

      mAdapter = new FaultAdapter(getContext(),titles); 

      recyclerViewFaults.setAdapter(mAdapter); 
     } else { 
      //TODO NO FAULTS 
     } 
    } 

これは追加してください。これは、これは私のarrays.xml

<string-array name="dtc_descrip"> 
     <item>Wiring, regulator control solenoid. </item> 
     <item>Wiring, regulator control solenoid. </item> 
     <item>Wiring short to earth, regulator control solenoid. </item> 
     <item>Wiring open circuit/short to positive, regulator control solenoid. </item> 
     <item>Wiring open circuit, fuel shut -off valve. </item> 
     <item>Wiring short to earth, fuel shut -off valve. </item> 
     <item>Wiring short to positive, fuel shut -off valve.</item> 
     <item>Mechanical fault. </item> 
     <item>Mechanical fault. </item> 
</string-array> 

<string-array name="dtc_keys"> 
      <item>P0001</item> 
      <item>P0002</item> 
      <item>P0003</item> 
      <item>P0004</item> 
      <item>P0005</item> 
      <item>P0006</item> 
      <item>P0007</item> 
      <item>P0008</item> 
      <item>P0009</item> 
      <item>P000A</item> 
      <item>P000B</item> 
      <item>P000C</item> 
      <item>P000D</item> 
      <item>P000E</item> 
      <item>P000F</item> 
</string-array> 

<string-array name="dtc_values"> 
      <item>Fuel Volume Regulator Control Circuit/Open</item> 
      <item>Fuel Volume Regulator Control Circuit Range/Performance</item> 
      <item>Fuel Volume Regulator Control Circuit Low</item> 
      <item>Fuel Volume Regulator Control Circuit High</item> 
      <item>Fuel Shutoff Valve A Control Circuit/Open</item> 
      <item>Fuel Shutoff Valve A Control Circuit Low</item> 
      <item>Fuel Shutoff Valve A Control Circuit High</item> 
      <item>Engine Position System Performance</item> 
      <item>Engine Position System Performance</item> 
      <item>A Camshaft Position Slow Response</item> 
      <item>B Camshaft Position Slow Response</item> 
      <item>A Camshaft Position Slow Response</item> 
      <item>B Camshaft Position Slow Response</item> 
      <item>Fuel Volume Regulator Control Exceeded Learning Limit</item> 
      <item>Fuel System Over Pressure Relief Valve Activated</item> 
      <item>A Camshaft Position Actuator Circuit/Open</item> 
      <item>A Camshaft Position - Timing Over-Advanced or System Performance</item> 
      <item>Camshaft variable timing control - Bank 1 - performance</item> 
      <item>A Camshaft Position - Timing Over-Retarded</item> 
</string-array> 

答えて

0

で説明してタイトルのgetセットクラス

public class FaultDesc { 

    private String faultDesc, mFaultTitle; 

    public FaultDesc(String dtccode, String faultDesc) { 
     this.faultDesc = faultDesc; 
     this.mFaultTitle = dtccode; 
    } 

    public String getFaultDesc() { 
     return faultDesc; 
    } 

    public String getmFaultTitle() { 
     return mFaultTitle; 
    } 
} 

public class FaultDescViewHolder extends ChildViewHolder { 

    private TextView mFaultDesc; 
    Context c; 

    public FaultDescViewHolder(View itemView) { 
     super(itemView); 

     mFaultDesc = (TextView) itemView.findViewById(R.id.fault_desc); 
    } 

    public void bind(FaultDesc desc) { 
     mFaultDesc.setText(desc.getmFaultTitle()+" - "+ desc.getFaultDesc()); 
    } 
} 

ある

public class FaultAdapter extends ExpandableRecyclerAdapter<FaultTitleViewHolder,FaultDescViewHolder> { 

    private LayoutInflater mInflator; 
    private List<FaultTitle> mTitleList; 

    public FaultAdapter(Context context, @NonNull List<FaultTitle> parentItemList) { 
     super(parentItemList); 
     mTitleList = parentItemList; 
     mInflator = LayoutInflater.from(context); 
    } 

    @Override 
    public FaultTitleViewHolder onCreateParentViewHolder(@NonNull ViewGroup parentViewGroup) { 
     View movieCategoryView = mInflator.inflate(R.layout.view_fault_title, parentViewGroup, false); 
     return new FaultTitleViewHolder(movieCategoryView); 
    } 

    @Override 
    public FaultDescViewHolder onCreateChildViewHolder(@NonNull ViewGroup childViewGroup) { 
     View moviesView = mInflator.inflate(R.layout.view_fault_desc, childViewGroup, false); 
     return new FaultDescViewHolder(moviesView); 
    } 

    @Override 
    public void onBindParentViewHolder(FaultTitleViewHolder faultTitleViewHolder, int position, @NonNull ParentListItem parentListItem) { 
     FaultTitle faultTitle = (FaultTitle) parentListItem; 
     faultTitleViewHolder.bind(faultTitle); 
    } 

    @Override 
    public void onBindChildViewHolder(FaultDescViewHolder faultDescViewHolder, int position, @NonNull Object childListItem) { 
     FaultDesc faultDesc = (FaultDesc) childListItem; 
     faultDescViewHolder.bind(faultDesc); 
    } 
} 

アダプタクラスですy私たちのFaultAdapterコード& xmlsどのように指示することができるように

+0

遅れて申し訳ありません!私はあなたが言ったように、私の質問を更新した、それを通過して助けてください! –

関連する問題