2016-07-26 8 views
0

解決策をお探しですか?テキストに応じてアイテムの色を変更する必要があります。 下に、ExpandableListAdapterのフラグメントがあります。それは正しく動作しますが、上下にスクロールするとすべてのアイテムが同じ色になります。それに対する解決策はありますか?ExpandableList表示アイテムの色を表示

@Override 
public View getChildView(int groupPosition, final int childPosition, 
         boolean isLastChild, View convertView, ViewGroup parent) { 


final ListItem childText = (ListItem) getChild(groupPosition, childPosition); 

    if (convertView == null) { 
     LayoutInflater infalInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     convertView = infalInflater.inflate(R.layout.list_item, null); 
    } 

    final TextView txtListChild = (TextView) convertView.findViewById(R.id.lblListItem); 

    txtListChild.setText(childText.getName()); 
    txtListChild.setTag(childText.getDocumentGuid()); 

    txtListChild.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 

       if (!txtListChild.getTag().equals("HEADER")) { 
        Toast.makeText(getApplicationContext(), "" + txtListChild.getTag(), Toast.LENGTH_LONG).show(); 

       } else { 
        //header// 

      } 
     } 
    }); 

    if(childText.getDocumentGuid().equals("HEADER")) { 
     txtListChild.setTextColor(context.getResources().getColor(R.color.color_accent)); 
    } 

    return convertView; 
    } 

答えて

0

まず、私が間違っている場合は、ListViewもスクリーンを通過して移動ビューを「リサイクルし」RecyclerViewの前身である私を修正してください。したがって、追加する必要があるものはelseです。if

if(childText.getDocumentGuid().equals("HEADER")) { 
    txtListChild.setTextColor(context.getResources().getColor(R.color.color_accent)); 
} else { 
txtListChild.setTextColor(context.getResources().getColor(R.color.color_something_else)) 
} 
関連する問題