我在listView中有2个视图,if (position == 0)
一次又一次地再次调用如何阻止它?
1: - 我希望微调器更改值,然后notifyDataSetChanged();
更新列表
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
int viewType = getItemViewType(position);
switch (viewType) {
case LAYOUT_ZERO_INDEX:
holder.materialDesignSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String item = parent.getItemAtPosition(position).toString();
Toast.makeText(parent.getContext(), "" + position, Toast.LENGTH_LONG).show();
if (position == 0) {
dataarry.clear();
dataarry.add(0, 1000);
dataarry.add(1, 5000);
dataarry.add(2, 6000);
dataarry.add(3, 8000);
dataarry.add(4, 3500);
dataarry.add(5, 4000);
dataarry.add(6, 5500);
notifyDataSetChanged();
setData(6, 8000, holder);
holder.mChart.invalidate();
}
if (position == 1) {
dataarry.clear();
dataarry.add(0, 5500);
dataarry.add(1, 4500);
dataarry.add(2, 5200);
dataarry.add(3, 7000);
dataarry.add(4, 7000);
dataarry.add(5, 6000);
dataarry.add(6, 7800);
// mChart.getData().notifyDataChanged();
// mChart.notifyDataSetChanged();
// mChart.clear();
notifyDataSetChanged();
setData(6, 8000, holder);
holder.mChart.invalidate();
// setData(6, 8000);
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>
(context, android.R.layout.simple_dropdown_item_1line, weeklist);
holder.materialDesignSpinner.setAdapter(arrayAdapter);
holder.mChart.setDrawBarShadow(false);
setData(6, 8000, holder);
if (position == 1) {
holder.year.setText("ahmad");
holder.year.setText("Mon,Oct 2");
holder.earning.setText("Rs 1200");
holder.trips.setText("10 سفر");
}
break;
}
}
答案 0 :(得分:0)
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
int positonOld=0;
int viewType = getItemViewType(position);
switch (viewType) {
case LAYOUT_ZERO_INDEX:
holder.materialDesignSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if(position==positonOld){
{
return;
}
positonOld=positon;
String item = parent.getItemAtPosition(position).toString();
Toast.makeText(parent.getContext(), "" + position, Toast.LENGTH_LONG).show();
if (position == 0) {
dataarry.clear();
dataarry.add(0, 1000);
dataarry.add(1, 5000);
dataarry.add(2, 6000);
dataarry.add(3, 8000);
dataarry.add(4, 3500);
dataarry.add(5, 4000);
dataarry.add(6, 5500);
notifyDataSetChanged();
setData(6, 8000, holder);
holder.mChart.invalidate();
}
if (positionn == 1) {
dataarry.clear();
dataarry.add(0, 5500);
dataarry.add(1, 4500);
dataarry.add(2, 5200);
dataarry.add(3, 7000);
dataarry.add(4, 7000);
dataarry.add(5, 6000);
dataarry.add(6, 7800);
// mChart.getData().notifyDataChanged();
// mChart.notifyDataSetChanged();
// mChart.clear();
notifyDataSetChanged();
setData(6, 8000, holder);
holder.mChart.invalidate();
// setData(6, 8000);
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>
(context, android.R.layout.simple_dropdown_item_1line, weeklist);
holder.materialDesignSpinner.setAdapter(arrayAdapter);
holder.mChart.setDrawBarShadow(false);
setData(6, 8000, holder);
if (position == 1) {
holder.year.setText("ahmad");
holder.year.setText("Mon,Oct 2");
holder.earning.setText("Rs 1200");
holder.trips.setText("10 سفر");
}
break;
}
}