2011-09-17 70 views
0

進出口使用下面的代碼使用過濾的ListView: How to dynamically update a ListView on Android定製ListAdapter用於過濾的ListView

,我試圖讓在ListView文本顏色爲黑色。顯然這隻能通過使用我之前製作的自定義適配器來完成。問題是如果我切換到自定義適配器,我的ListView沒有得到適當的篩選。有任何想法嗎?繼承人的代碼:

public class OffCampusStopsAdapter extends ArrayAdapter<String> { 
private final Context context; 
private final String[] names; 

public OffCampusStopsAdapter(Context context, String[] names) { 
    super(context, R.layout.rowlayout, names); 
    this.context = context; 
    this.names = names; 

} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View rowView = inflater.inflate(R.layout.offcampusstopslayout, null, true); 
    TextView textView = (TextView) rowView.findViewById(R.id.stoplabel); 
    textView.setText(names[position]); 
    String s = names[position]; 

    return rowView; 
} 

}

回答

0

我這樣做是這樣的:

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


    //Get the current alert object 
    Al al = getItem(position); 

    //Inflate the view 
    if(convertView==null) 
    { 
     alertView = new LinearLayout(getContext()); 
     String inflater = Context.LAYOUT_INFLATER_SERVICE; 
     LayoutInflater vi; 
     vi = (LayoutInflater)getContext().getSystemService(inflater); 
     vi.inflate(resource, alertView, true); 
    } 
    else 
    { 
     alertView = (LinearLayout) convertView; 
    } 
    //Get the text boxes from the listitem.xml file 
    TextView alertText =(TextView)alertView.findViewById(R.id.txtAlertText); 
    TextView alertDate =(TextView)alertView.findViewById(R.id.txtAlertDate); 

    //Assign the appropriate data from our alert object above 

    alertText.setTypeface(font); 
    alertDate.setTypeface(font); 
    alertText.setText(al.getOfficeName()); 
    alertDate.setText(al.getAddress()); 


    return alertView; 
}