我有一个ExpandableListView
列表工作得很好但我想当我点击Childs一个时钟图标改变颜色并做一些事情并保存但当我点击孩子时第一个时钟第一个孩子做了工作,但当我向下滚动一个随机的孩子或者其中2 3 3也会改变颜色,如果我关闭应用程序这个os我的适配器代码将保存
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);
}
这是我的片段代码,Clock类是Clock Icon
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方法内部工作时,您在其中使用IF条件,然后尝试使用“else”。 在你的情况下,我可以看到'if'和'else if',而
否则
缺失。
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);
}
可以转换为
$spilt=explode(',',$newstyle);
foreach ($spilt as $splitkey => $splitvalue) {
if ($splitkey == 0) {
$this->db->where("FIND_IN_SET(".$splitvalue.",w_card_style)!=",0);
}
else{
$this->db->or_where("FIND_IN_SET(".$splitvalue.",w_card_style)!=",0);
}
}