У меня проблема с getView при добавлении элементов в ListView с помощью BaseAdapter. Когда я сохраняю «от 0 до 15 элементов», например, «if(position == 0 )
до if(position == 15)
», он последовательно отображает все элементы ListView. Когда я пытаюсь добавить еще один (16-й) элемент в ListView (например, if(position == 16)
), он отображает первый элемент в ListView и не показывает 16-й элемент, который я добавил в массив.
Я использую пользовательскую строку ListView, и каждая строка имеет свою собственную функцию, которая взаимодействует с пользователями. Но я не знаю, как добавить более 16 элементов в getView, используя «позицию».
У меня есть список из 21 элемента, но я не могу реализовать более 16 элементов.
У кого-нибудь есть решение этого, чем, пожалуйста, скажите мне
Получить код
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Holder holder;
TextView tv1;
ImageView img;
TextView desc;
LayoutInflater inflater = context.getLayoutInflater();
if(convertView == null){
convertView = inflater.inflate(R.layout.screenlock_addapter, parent,false);
holder = new Holder();
if(position == 0 ){
holder.htv = (TextView) convertView.findViewById(R.id.scl_tv);
holder.himg = (ImageView) convertView.findViewById(R.id.scl_img);
holder.hdesc = (TextView) convertView.findViewById(R.id.scl_desc);
holder.htv.setText(Listitem[position]);
holder.hdesc.setText(desc1[position]);
holder.himg.setImageResource(aimg[position]);
convertView.setTag(holder);
}
if(position == 1 ){
holder.htv = (TextView) convertView.findViewById(R.id.scl_tv);
holder.htv.setText(Listitem[position]);
convertView.setTag(holder);
}
if(position == 2 ){
holder.htv = (TextView) convertView.findViewById(R.id.scl_tv);
holder.himg = (ImageView) convertView.findViewById(R.id.scl_img);
holder.hdesc = (TextView) convertView.findViewById(R.id.scl_desc);
holder.htv.setText(Listitem[position]);
holder.hdesc.setText(desc1[position]);
holder.himg.setImageResource(aimg[position]);
convertView.setTag(holder);
}
if(position == 3 ){
holder.htv = (TextView) convertView.findViewById(R.id.scl_tv);
holder.himg = (ImageView) convertView.findViewById(R.id.scl_img);
holder.hdesc = (TextView) convertView.findViewById(R.id.scl_desc);
holder.htv.setText(Listitem[position]);
holder.hdesc.setText(desc1[position]);
holder.himg.setImageResource(aimg[position]);
convertView.setTag(holder);
}
if(position == 4 ){
holder.htv = (TextView) convertView.findViewById(R.id.scl_tv);
holder.himg = (ImageView) convertView.findViewById(R.id.scl_img);
holder.hdesc = (TextView) convertView.findViewById(R.id.scl_desc);
holder.htv.setText(Listitem[position]);
holder.hdesc.setText(desc1[position]);
holder.himg.setImageResource(aimg[position]);
convertView.setTag(holder);
}
if(position == 5 ){
holder.htv = (TextView) convertView.findViewById(R.id.scl_tv);
holder.himg = (ImageView) convertView.findViewById(R.id.scl_img);
holder.hdesc = (TextView) convertView.findViewById(R.id.scl_desc);
holder.htv.setText(Listitem[position]);
holder.hdesc.setText(desc1[position]);
holder.himg.setImageResource(aimg[position]);
convertView.setTag(holder);
}
if(position == 6 ){
holder.htv = (TextView) convertView.findViewById(R.id.scl_tv);
holder.himg = (ImageView) convertView.findViewById(R.id.scl_img);
holder.hdesc = (TextView) convertView.findViewById(R.id.scl_desc);
holder.htv.setText(Listitem[position]);
holder.hdesc.setText(desc1[position]);
holder.himg.setImageResource(aimg[position]);
convertView.setTag(holder);
}
if(position == 7 ){
holder.htv = (TextView) convertView.findViewById(R.id.scl_tv);
holder.himg = (ImageView) convertView.findViewById(R.id.scl_img);
holder.hdesc = (TextView) convertView.findViewById(R.id.scl_desc);
holder.htv.setText(Listitem[position]);
holder.hdesc.setText(desc1[position]);
holder.himg.setImageResource(aimg[position]);
convertView.setTag(holder);
}
if(position == 8 ){
holder.htv = (TextView) convertView.findViewById(R.id.scl_tv);
holder.himg = (ImageView) convertView.findViewById(R.id.scl_img);
holder.hdesc = (TextView) convertView.findViewById(R.id.scl_desc);
holder.htv.setText(Listitem[position]);
holder.hdesc.setText(desc1[position]);
holder.himg.setImageResource(aimg[position]);
convertView.setTag(holder);
}
if(position == 9 ){
holder.htv = (TextView) convertView.findViewById(R.id.scl_tv);
holder.himg = (ImageView) convertView.findViewById(R.id.scl_img);
holder.hdesc = (TextView) convertView.findViewById(R.id.scl_desc);
holder.htv.setText(Listitem[position]);
holder.hdesc.setText(desc1[position]);
holder.himg.setImageResource(aimg[position]);
convertView.setTag(holder);
}
if(position == 10 ){
holder.htv = (TextView) convertView.findViewById(R.id.scl_tv);
holder.himg = (ImageView) convertView.findViewById(R.id.scl_img);
holder.hdesc = (TextView) convertView.findViewById(R.id.scl_desc);
holder.htv.setText(Listitem[position]);
holder.hdesc.setText(desc1[position]);
holder.himg.setImageResource(aimg[position]);
convertView.setTag(holder);
}
if(position == 11 ){
holder.htv = (TextView) convertView.findViewById(R.id.scl_tv);
holder.himg = (ImageView) convertView.findViewById(R.id.scl_img);
holder.hdesc = (TextView) convertView.findViewById(R.id.scl_desc);
holder.htv.setText(Listitem[position]);
holder.hdesc.setText(desc1[position]);
holder.himg.setImageResource(aimg[position]);
convertView.setTag(holder);
}
if(position == 12 ){
holder.htv = (TextView) convertView.findViewById(R.id.scl_tv);
holder.himg = (ImageView) convertView.findViewById(R.id.scl_img);
holder.hdesc = (TextView) convertView.findViewById(R.id.scl_desc);
holder.htv.setText(Listitem[position]);
holder.hdesc.setText(desc1[position]);
holder.himg.setImageResource(aimg[position]);
convertView.setTag(holder);
}
if(position == 13 ){
holder.htv = (TextView) convertView.findViewById(R.id.scl_tv);
holder.himg = (ImageView) convertView.findViewById(R.id.scl_img);
holder.hdesc = (TextView) convertView.findViewById(R.id.scl_desc);
holder.htv.setText(Listitem[position]);
holder.hdesc.setText(desc1[position]);
holder.himg.setImageResource(aimg[position]);
convertView.setTag(holder);
}
if(position == 14 ){
holder.htv = (TextView) convertView.findViewById(R.id.scl_tv);
holder.himg = (ImageView) convertView.findViewById(R.id.scl_img);
holder.hdesc = (TextView) convertView.findViewById(R.id.scl_desc);
holder.htv.setText(Listitem[position]);
holder.hdesc.setText(desc1[position]);
holder.himg.setImageResource(aimg[position]);
convertView.setTag(holder);
}
if(position == 15 ){
holder.htv = (TextView) convertView.findViewById(R.id.scl_tv);
holder.himg = (ImageView) convertView.findViewById(R.id.scl_img);
holder.hdesc = (TextView) convertView.findViewById(R.id.scl_desc);
holder.htv.setText(Listitem[position]);
holder.hdesc.setText(desc1[position]);
holder.himg.setImageResource(aimg[position]);
convertView.setTag(holder);
}
if(position == position + 1 ){
holder.htv = (TextView) convertView.findViewById(R.id.scl_tv);
holder.himg = (ImageView) convertView.findViewById(R.id.scl_img);
holder.hdesc = (TextView) convertView.findViewById(R.id.scl_desc);
holder.htv.setText(Listitem[position]);
holder.hdesc.setText(desc1[position]);
holder.himg.setImageResource(aimg[position]);
convertView.setTag(holder);
}
if(position == position + 2 ){
holder.htv = (TextView) convertView.findViewById(R.id.scl_tv);
holder.himg = (ImageView) convertView.findViewById(R.id.scl_img);
holder.hdesc = (TextView) convertView.findViewById(R.id.scl_desc);
holder.htv.setText(Listitem[position]);
holder.hdesc.setText(desc1[position]);
holder.himg.setImageResource(aimg[position]);
convertView.setTag(holder);
}
if(position == position + 3 ){
holder.htv = (TextView) convertView.findViewById(R.id.scl_tv);
holder.himg = (ImageView) convertView.findViewById(R.id.scl_img);
holder.hdesc = (TextView) convertView.findViewById(R.id.scl_desc);
holder.htv.setText(Listitem[position]);
holder.hdesc.setText(desc1[position]);
holder.himg.setImageResource(aimg[position]);
convertView.setTag(holder);
}
if(position == position + 4 ){
holder.htv = (TextView) convertView.findViewById(R.id.scl_tv);
holder.himg = (ImageView) convertView.findViewById(R.id.scl_img);
holder.hdesc = (TextView) convertView.findViewById(R.id.scl_desc);
holder.htv.setText(Listitem[position]);
holder.hdesc.setText(desc1[position]);
holder.himg.setImageResource(aimg[position]);
convertView.setTag(holder);
}
if(position == position + 5 ){
holder.htv = (TextView) convertView.findViewById(R.id.scl_tv);
holder.himg = (ImageView) convertView.findViewById(R.id.scl_img);
holder.hdesc = (TextView) convertView.findViewById(R.id.scl_desc);
holder.htv.setText(Listitem[position]);
holder.hdesc.setText(desc1[position]);
holder.himg.setImageResource(aimg[position]);
convertView.setTag(holder);
}
}
else {
holder = (Holder) convertView.getTag();
}
return convertView;
}
@Override public int getCount() { // TODO Auto-generated method stub return Listitem.length; }
- person hardwork   schedule 15.05.2015