2013-07-09 3 views
0

У меня есть невероятная проблема с TextView в ListView. TextView на первой строке ListView имеет черный цвет на Android 4.2.2. (Nexus 4) На Android 4.2.1 и менее он не имеет цвета. На моем HTC One все было нормально, пока я не получил обновление до 4.2.2. Теперь TextView s на первых двух строках имеют черный фон. screenshot от Nexus с первым черным цветом говорят больше.Черный фон на Android 4.2.2

код адаптера ниже:

public class NotificationsAdapter extends ArrayAdapter<Object> { 

private ArrayList<Object> items; 
Context context;  
private LayoutInflater mInflater; 
Typeface rb; 
Typeface bn; 
Typeface rr; 
Typeface rbc; 

public NotificationsAdapter(Context context, int textViewResourceId, ArrayList<Object> items) { 
     super(context, textViewResourceId, items);  
     this.context = context;    
     this.items = items; 
     mInflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     rb = Typeface.createFromAsset(getContext().getAssets(), "Roboto-Bold.ttf"); 
     bn = Typeface.createFromAsset(getContext().getAssets(), "BebasNeue.otf"); 
     rr = Typeface.createFromAsset(getContext().getAssets(), "Roboto-Regular.ttf"); 
     rbc = Typeface.createFromAsset(getContext().getAssets(), "Roboto-BoldCondensed.ttf"); 
} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) {  

     int type; 
     if(items.get(position).getClass().equals(String.class)) 
      type = 0; 
     else 
      type = 1;   

     if(type == 0){ 
      String m = (String)items.get(position); 
      if (m != null) {     
       convertView = mInflater.inflate(R.layout.notification_month_row, null); 
       TextView month_date = (TextView)convertView.findViewById(R.id.tw_notification_month); 
       month_date.setTypeface(rb); 
       month_date.setText(m);      
      } 
     } 
     else{       
      Notifications o = (Notifications)items.get(position); 
      if (o != null) { 
       convertView = mInflater.inflate(R.layout.notification_row, null); 
       TextView month_date = (TextView)convertView.findViewById(R.id.tw_notification_date); 
       TextView title = (TextView)convertView.findViewById(R.id.tw_notification_title); 
       TextView note = (TextView)convertView.findViewById(R.id.tw_notification_description); 
       ImageView mark = (ImageView)convertView.findViewById(R.id.iv_notification_marker); 
       title.setTypeface(bn); 
       title.setText(o.getTitle());      
       note.setTypeface(rr); 
       note.setText(o.getDescription());      
       month_date.setTypeface(rbc); 
       month_date.setText(o.getDate());       
       if(o.getConfirmed().equals("1")){ 
        mark.setVisibility(4); 
       }else{ 
        mark.setVisibility(0); 
       }          
      } 
     } 

     return convertView; 
    } 

Кто-нибудь есть какие-либо идеи, почему это происходит?

XML здесь:

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"  
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:layout_margin="0dp" 
android:paddingTop="0dp" 
android:paddingBottom="25dp"  
android:background="@drawable/background_cell_profile"  
>  


<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 
<TextView 
     android:id="@+id/tw_notification_title"    
     android:layout_toLeftOf="@+id/tw_notification_date" 
     android:layout_alignParentLeft="true" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content"    
     android:layout_marginTop="25dp"   
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:lines="1"  
     android:singleLine="true" 
     android:ems="3"  
     android:ellipsize="end"   
     android:textSize="27sp" 
     android:textColor="#ffffff" 
     android:shadowColor="#000000" 
     android:shadowDy="-2" 
     android:shadowRadius="0.1" 
     android:clickable="false" 
     android:focusable="false"/> 

<TextView 
     android:id="@+id/tw_notification_date" 
     android:layout_marginTop="25dp" 
     android:layout_alignParentRight="true"   
     android:layout_marginLeft="10dp"    
     android:layout_marginRight="10dp"   
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content"        
     android:textSize="20sp" 
     android:textColor="#ffffff" 
     android:shadowColor="#000000" 
     android:shadowDy="-2" 
     android:shadowRadius="0.1" 
     android:clickable="false" 
     android:focusable="false"/> 

<TextView 
     android:id="@+id/tw_notification_description" 
     android:layout_below="@+id/tw_notification_title" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content"    
     android:layout_marginLeft="10dp" 
     android:layout_marginTop="10dp" 
     android:layout_marginRight="10dp"         
     android:textSize="14sp" 
     android:textColor="@color/gray_to_white" 
     android:shadowColor="#000000" 
     android:shadowDy="-2" 
     android:shadowRadius="0.1" 
     android:clickable="false" 
     android:focusable="false"/>  
</RelativeLayout> 

<ImageView 
    android:id="@+id/iv_notification_marker" 
    android:layout_width="40dp" 
    android:layout_height="40dp" 
    android:padding="0dp" 
    android:layout_marginTop="0dp" 
    android:layout_gravity="right|top" 
    android:src="@drawable/icon_oznameni_unreadindicator"/> 

+0

Вы можете разместить файл XML для пользовательского списка вид товара? – Nick

+0

Я разместил XML выше – dostalleos

+0

Он вызван тенью, потому что он меняет цвет с теневым цветом. Но я до сих пор не знаю, почему это происходит только на первой или первой + второй строке на Android 4.2.2. – dostalleos

ответ

0

Не уверен, если это поможет, но вы используете LayoutInflater неправильно:

convertView = mInflater.inflate(R.layout.notification_month_row, null); 

Это должно скорее быть:

convertView = mInflater.inflate(R.layout.notification_month_row, parent, false); 

Используя fo rmer иногда выдавал мне странные проблемы с рендерингом.

см this blog post

+0

Спасибо, я попробовал, но я получаю NullPointerException на title.setTypeface (bn) ;. Компоненты пользовательского интерфейса из макета - null :( – dostalleos

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