0

У меня есть ListView с пользовательским адаптером, но когда прокрутки в ListView скрыты некоторые элементы: enter image description hereListView с пользовательским адаптером: некоторые элементы скрыты

Из образа вы можете увидеть, что из A69 переходит на А72 оставляя скрытые пункты a70 и a71.

Вот код пользовательского адаптера:

public NewCurrenciesAdapter(ArrayList<NewCurrencyData> list, Context context) { 
    m_list = list; 
    m_context = context; 
    m_layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
} 

@Override 
public int getCount() { 
    return m_list.size(); 
} 

@Override 
public Object getItem(int position) { 
    return m_list.get(position); 
} 

@Override 
public long getItemId(int position) { 
    return position; 
} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
    if (convertView == null) { 
     convertView = m_layoutInflater.inflate(R.layout.addcurrency_item, parent, false); 
    } 

    TextView currencyName = (TextView) convertView.findViewById(R.id.textCurrencyName); 
    currencyName.setText("a" + position); 

    ImageView currencyImage = (ImageView) convertView.findViewById(R.id.imageCurrencyCountry); 

    currencyImage.setImageResource(getImageId(m_context, "c" + m_list.get(position).name.toLowerCase())); 

    if (m_list.get(position).checked) { 
     convertView.setBackgroundResource(android.R.color.holo_green_dark); 
    } 
    else { 
     convertView.setBackgroundResource(android.R.color.background_light); 
    } 

    return convertView; 
} 

EDIT: Вот макет деятельности:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"> 

    <ListView 
     android:id="@+id/ListViewAllCurrencies" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.8"> 
    </ListView> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:text="Apply" 
      android:id="@+id/buttonAdd" 
      android:layout_weight=".50" 
      android:onClick="applyChange"/> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:text="Cancel" 
      android:id="@+id/buttonCancel" 
      android:layout_weight=".50" 
      android:onClick="cancelChange"/> 
    </LinearLayout> 


</LinearLayout> 

И addcurrency_item:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

    <ImageView 
     android:id="@+id/imageCurrencyCountry" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/cusd" 
     android:contentDescription="" /> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/textCurrencyName" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:gravity="center_vertical" 
      android:layout_marginLeft="5dp" 
      android:layout_marginStart="5dp" 
      android:textSize="20sp" 
      android:text="Currency name"/> 
    </RelativeLayout> 


</LinearLayout> 
+0

Похоже, у вас проблема в файле макета. Поделитесь файлом макета, имеющим список и кнопки. –

+0

Если вы используете относительный макет, установите его в виде списка layout_above = "@ + id/button layout id". –

ответ

0

отлаживать ИНТ Возврат: getImageId(m_context, "c" + m_list.get(position).name.toLowerCase()

Вероятно, он возвращает 0 или -1, который не устанавливает изображения в вашем представлении изображения, и представление свернуто!

+0

Спасибо! Комментирование строк с ImageView решило проблему. – AlexxanderX

Смежные вопросы