我有一个带有 Spinner 的自定义 ListView ,其中包含 ListArray 。
没有 ListView Scroll ,它可以正常工作
但是,当我向自定义 ListView 添加一些项目时,我在 Spinner 上选择了第一项或第二项,然后向下滚动 ListView (直到该行消失)我看到底部项目上的另一个 Spinner 将被选中(如上部)
保留了我的选择,但选择底部 ListView 上的另一个 Spinner
我的代码是:
public class SoundListView extends ArrayAdapter<String>{
List<String> DataList;
private final Activity context;
private ViewGroup vg;
int startTimer, stopTimer,rPosition;
String fileTagName = "",externalTagFileName = "",tagFileName= "",fileName = "";
public SoundListView (Activity context, ArrayList arrSubject, ArrayList arrDurationSplit, ArrayList ids,ArrayList arrFileName,ArrayList arrDuration,ArrayList arrIdTag,ArrayList arrTagName,ArrayList arrMainId,ArrayList arrStartTime, ArrayList arrStopTime) {
super(context, R.layout.activity_list, arrSubject);
this.context = context;
this.arrSubject = arrSubject;
this.arrDurationSplit = arrDurationSplit;
this.arrIdTag = arrIdTag;
this.arrDuration = arrDuration;
this.arrTagName = arrTagName;
this.arrMainId = arrMainId;
this.arrStartTime = arrStartTime;
this.arrStopTime = arrStopTime;
this.arrFileName = arrFileName;
this.ids = ids;
}
private ArrayList arrSubject = new ArrayList();
private ArrayList arrDurationSplit = new ArrayList();
private ArrayList ids = new ArrayList();
private ArrayList arrIdTag = new ArrayList();
private ArrayList arrTagName = new ArrayList();
private ArrayList arrMainId = new ArrayList();
private ArrayList arrStartTime = new ArrayList();
private ArrayList arrStopTime = new ArrayList();
private ArrayList arrDuration = new ArrayList();
private ArrayList arrFileName = new ArrayList();
final private ArrayList<String> arrayTasPath = new ArrayList<String>();
static class ViewHolder {
ImageView imgPlaySound,imgShareList;
TextView txtCaption,txtDynamicTimer,txtDurationSplit,txtTotalTimer,txtHiden;
Spinner spTags;
SeekBar seekBar1;
LinearLayout linearSeek;
int position;
}
@Override
public View getView(final int position,View convertView, final ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
vg = parent;
final ArrayList arrTagNameTemp = new ArrayList();
final ArrayList arrStartTimeTemp = new ArrayList();
final ArrayList arrStopTimeTemp = new ArrayList();
arrTagNameTemp.add("all");
final ViewHolder viewHolder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.listview, null);
viewHolder = new ViewHolder();
viewHolder.position = position;
viewHolder.txtCaption = (TextView) convertView.findViewById(R.id.txtCaption);
viewHolder.txtDynamicTimer = (TextView) convertView.findViewById(R.id.txtDynamicTimer);
viewHolder.txtDurationSplit = (TextView) convertView.findViewById(R.id.txtTotalTimer);
viewHolder.imgPlaySound = (ImageView) convertView.findViewById(R.id.imgPlaySound);
viewHolder.imgShareList = (ImageView) convertView.findViewById(R.id.imgShareList);
viewHolder.linearSeek = (LinearLayout) convertView.findViewById(R.id.linearSeek);
viewHolder.spTags = (Spinner) convertView.findViewById(R.id.spTags);
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(context,android.R.layout.simple_spinner_item, arrTagNameTemp);
viewHolder.spTags.setAdapter(adapter);
viewHolder.spTags.setSelection(0);
final int duration = Integer.valueOf(arrDuration.get(position).toString());
for(int i = 0; i < arrMainId.size(); i++)
{
if (Integer.valueOf(arrMainId.get(i).toString()) == Integer.valueOf(ids.get(position).toString()))
{
arrTagNameTemp.add(arrTagName.get(i));
arrStartTimeTemp.add(arrStartTime.get(i));
arrStopTimeTemp.add(arrStopTime.get(i));
}
}
//////////////////////////////////////////////////////////////////////////////
convertView.setTag(viewHolder);
}
else
{
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.txtCaption.setText(arrSubject.get(position).toString());
return convertView;
}
有人能帮助我吗?
答案 0 :(得分:0)
首先告诉我为什么你使用那么多的arraylists,你不能只使用一个自定义数据类型。在该单个数组中,所有值都将相互关联,并且很容易管理它们。
我建议的解决方案是创建一个包含自定义数据类型的ArrayList,包括上面给出的所有arraylists的所有值。并且不要在适配器中初始化您的Array。在您设置适配器的位置初始化并添加值(在您的活动中)。你必须在主阵列中添加一个参数,让我们说&#34; selectedValue&#34;,默认情况下它将是&#34; all&#34;但是当用户选择某个值时,您将更新该特定位置上的项目值。
然后在你的getView方法中,你将检查&#34; selectedValue&#34;的值。对于每个项目,如果它等于&#34; all&#34;那么你将设置它,否则你将设置&#34; selectedValue&#34;的值。对你的微调器。请记住一件事,你必须在if和else子句中为每个项目的spinner设置一个值。