2017-12-16 19 views
0

私はExpandableListViewを持っていますが、Listはうまくいきますが、Childsの時計アイコンをクリックして何かをして保存したいのですが、クロック最初の子は、仕事をするが、私は、ランダムな子を下にスクロールするか、多分それらの2 O 3があまりにも色が変わりますし、私はアプリを閉じた場合、それが保存されたときに、これは私のアダプターコードアンドロイドExpandable ListViewのChildClick Listnerが機能していない

public class exTourListAdapter extends BaseExpandableListAdapter { 

private Context context; 
private ArrayList<GroupTour> groups; 
private int count; 
SharedPreferences preferences; 
AppCompatTextView timeTour ,tvPrize ,tvGameMode,tvBuyIn,tvLateReg 
,tvReBuy,tvDays; 
RelativeLayout childToursLayout; 


Clock clock ; 
public exTourListAdapter(Context context , ArrayList<GroupTour> groups,int count) { 
    this.context = context; 
    this.groups = groups; 
    this.count = count; 
} 

@Override 
public ChildTour getChild(int groupPosition, int childPosition) { 
    GroupTour group = groups.get(groupPosition); 
    exChild exchild = group.getChildren().get(groupPosition); 
    ChildTour child = exchild.getChildTours().get(childPosition); 
    return child; 
} 

@Override 
public long getChildId(int groupPosition, int childPosition) { 
    ChildTour childTour= getChild(groupPosition,childPosition); 
    int id= childTour.getTourId(); 
    return id; 
} 

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

    ChildTour child = getChild(groupPosition, 
      childPosition); 
    if (convertView == null) { 
     LayoutInflater infalInflater = (LayoutInflater) context 
       .getSystemService(context.LAYOUT_INFLATER_SERVICE); 
     convertView = infalInflater.inflate(R.layout.ex_list_tours_child, null); 
    } 
    preferences = context.getSharedPreferences("timeonoff",Context.MODE_PRIVATE); 

    timeTour = (AppCompatTextView) convertView.findViewById(R.id.time_tour); 
    tvPrize = (AppCompatTextView) convertView.findViewById(R.id.tour_prize); 
    tvGameMode = (AppCompatTextView) convertView.findViewById(R.id.tour_gamemode); 
    tvBuyIn = (AppCompatTextView) convertView.findViewById(R.id.tour_buy_in); 
    tvLateReg = (AppCompatTextView) convertView.findViewById(R.id.tour_late_reg); 
    tvReBuy = (AppCompatTextView) convertView.findViewById(R.id.tour_rebuy); 
    tvDays = (AppCompatTextView) convertView.findViewById(R.id.tour_days); 
    clock = (Clock) convertView.findViewById(R.id.clock_layour); 
    tvDays.setTag(child.getTourId()); 
    clock.setHours(child.getHour()); 
    clock.setMinutes(child.getMin()); 

    tvLateReg.setText("Late Register: "+child.getLateReg()+" min"); 
    int id = (int) getChildId(groupPosition,childPosition); 
    if (preferences.getBoolean("time"+id,false) == true){ 
     clock.setClockColor(R.color.material_green_500); 
    }else if (preferences.getBoolean("time"+id,true)==false){ 
     clock.setClockColor(R.color.material_brown_700); 
    } 
    if (child.getReBuy().equals("")){ 
     tvReBuy.setText("Rebuy: ?"); 
    }else { 
     tvReBuy.setText("Rebuy: "+child.getReBuy()); 
    } 
    tvDays.setText(child.getDay()); 
    tvBuyIn.setText("BuyIn: "+child.getBuyIn()); 
    tvGameMode.setText(child.getGameMode()); 
    tvPrize.setText(child.getPrize()); 
    timeTour.setText(child.getTime()); 
    return convertView; 

} 

@Override 
public int getChildrenCount(int groupPosition) { 
    int number = groups.get(groupPosition).getChildren().get(groupPosition).getChildNumbers(); 

    return number; 
} 

@Override 
public GroupTour getGroup(int groupPosition) { 
    // TODO Auto-generated method stub 
    return groups.get(groupPosition); 
} 

@Override 
public int getGroupCount() { 
    // TODO Auto-generated method stub 
    return groups.size(); 
} 

@Override 
public long getGroupId(int groupPosition) { 
    // TODO Auto-generated method stub 
    return groupPosition; 
} 

@Override 
public View getGroupView(int groupPosition, boolean isExpanded, 
         View convertView, ViewGroup parent) { 
    GroupTour group = getGroup(groupPosition); 
    if (convertView == null) { 
     LayoutInflater inf = (LayoutInflater) context 
       .getSystemService(context.LAYOUT_INFLATER_SERVICE); 
     convertView = inf.inflate(R.layout.list_header_groups_tours, null); 
    } 
    TextView tv = (TextView) convertView.findViewById(R.id.tours_site_name); 
    tv.setText(group.getName()); 
    // TODO Auto-generated method stub 
    return convertView; 
} 

@Override 
public boolean hasStableIds() { 
    // TODO Auto-generated method stub 
    return true; 
} 

@Override 
public boolean isChildSelectable(int groupPosition, int childPosition) { 
    // TODO Auto-generated method stub 
    return true; 
} 
public void onClockClick(View view){ 
    clock.setClockColor(R.color.material_red_300); 
} 

、これをOS私のフラグメントコードです。クロッククラスは時計アイコンです

public class ListToursexFragment extends Fragment { 
SwipeRefreshLayout refresh; 
ExpandableListView listView; 
SharedPreferences.Editor editor; 
SharedPreferences pref; 
@Nullable 
@Override 
public View onCreateView(LayoutInflater inflater, 
         @Nullable ViewGroup container, 
         @Nullable Bundle savedInstanceState) { 
    View view= inflater.inflate(R.layout.activity_tours,container,false); 
    pref= getActivity().getSharedPreferences("timeonoff", Context.MODE_PRIVATE); 
    editor =pref.edit(); 
    refresh = (SwipeRefreshLayout) view.findViewById(R.id.refresh_tours); 
    listView = (ExpandableListView) view.findViewById(R.id.list_tours); 
    refresh.setColorSchemeColors(
      R.color.material_green_200, 
      R.color.material_green_400, 
      R.color.material_green_600, 
      R.color.material_green_800 
    ); 
    refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { 
     @Override 
     public void onRefresh() { 
      prepareData(url,listView); 
     } 
    }); 
    prepareData(url,listView); 
    return view; 
} 

private void prepareData(String url, final ExpandableListView listView) { 
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() { 
     @Override 
     public void onResponse(JSONObject response) { 
      try { 

       JSONArray array = response.getJSONArray("sites"); 
       int count = response.getInt("sitescount"); 
       exTourParser parser = new exTourParser(); 
       final ArrayList<GroupTour> items = parser.Parse(array); 

       exTourListAdapter adapter = new exTourListAdapter(getContext(), items,count); 
       listView.setAdapter(adapter); 
       listView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { 
        @Override 
        public boolean onChildClick(ExpandableListView expandableListView, View view, int i, int i1, long id) { 
         Clock clock = (Clock) view.findViewById(R.id.clock_layour); 
         boolean b= pref.getBoolean("time"+id,false); 
         if (b ==true){ 
          editor.putBoolean("time"+id,false); 
          editor.commit(); 
          clock.setClockColor(R.color.material_brown_700); 
         }else if (b == false){ 
          editor.putBoolean("time"+id,true); 
          editor.commit(); 
          clock.setClockColor(R.color.material_green_700); 
         } 
         return false; 

        } 
       }); 
      } catch (JSONException e) { 
       e.printStackTrace(); 
      } 
     } 
    }, new Response.ErrorListener() { 
     @Override 
     public void onErrorResponse(VolleyError error) { 
      Toast.makeText(getContext(), "ridiok", Toast.LENGTH_SHORT).show(); 
     } 
    }); 
    RequestQueue quew = Volley.newRequestQueue(getActivity().getApplicationContext()); 
    quew.add(request); 
} 
​​が唯一の最初の子をクリックして0

と、この画面ショットは、その後、この起こった黒がデフォルトカラー

答えて

0

あなたはアダプタのgetViewメソッドメソッド内で作業中であり、その内部の状態が続いていしようとした場合、使用している数回スクロール"else"も。

が欠落している間、あなたのケースでは、私は、 '場合' と 'それ以外の場合は' を参照することができます。

if (b ==true) 
{ 
      editor.putBoolean("time"+id,false); 
      editor.commit(); 
      clock.setClockColor(R.color.material_brown_700); 
} 
else if (b == false) 
{ 
      editor.putBoolean("time"+id,true); 
      editor.commit(); 
      clock.setClockColor(R.color.material_green_700); 
} 

if (b) 
    { 
       editor.putBoolean("time"+id,false); 
       editor.commit(); 
       clock.setClockColor(R.color.material_brown_700); 
    } 
    else 
    { 
       editor.putBoolean("time"+id,true); 
       editor.commit(); 
       clock.setClockColor(R.color.material_green_700); 
    } 
に変換することができ
関連する問題