2012-02-20 144 views
0

我創建了一個自定義listview,它從數據庫加載數據。這些數據會被帶入一個數組中。使用自定義ListView滾動問題

我可以得到所有的數據來顯示它應該在列表視圖上。所以沒有問題。 我遇到的問題是滾動。當我滑動列表視圖時,它看起來運行緩慢。

下面是我的代碼的摘錄:

static class ViewHolder { 
    public TextView txtTitle; 
    public TextView txtDescription; 
    public TextView txtLocations; 
    public TextView txtShowingDate; 
    public TextView txtAdded; 
    public TextView txtProvider; 
    public TextView txtTicketUrl; 
    public ImageView imgProviderImage; 
    } 

public class FilmItemAdapter extends ArrayAdapter<FilmRecord> { 
    public ArrayList<FilmRecord> films; 

    public FilmItemAdapter(Context context, int textViewResourceId, ArrayList<FilmRecord> films) { 
     super(context, textViewResourceId, films); 
     this.films = films; 
    } 

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

     ViewHolder viewHolder = new ViewHolder(); 
     if (convertView == null) { 
      /* There is no view at this position, we create a new one. 
       In this case by inflating an xml layout */ 
      LayoutInflater inflater = LayoutInflater.from(getContext()); 
      convertView = inflater.inflate(R.layout.listitem, null); 

      // Creates a ViewHolder and store references to the two children views 
      // we want to bind data to. 
      //Find find by ID once, and store details in holder. 
      viewHolder.txtTitle = (TextView)convertView.findViewById(R.id.filmtitle); 
      viewHolder.txtShowingDate = (TextView) convertView.findViewById(R.id.filmshowingtime); 
      viewHolder.txtAdded = (TextView) convertView.findViewById(R.id.filmadded); 
      viewHolder.txtLocations = (TextView) convertView.findViewById(R.id.filmlocations); 
      viewHolder.txtDescription = (TextView) convertView.findViewById(R.id.filmdescription); 
      viewHolder.txtProvider = (TextView) convertView.findViewById(R.id.filmprovider); 
      viewHolder.txtTicketUrl = (TextView) convertView.findViewById(R.id.filmticketurl); 
      viewHolder.imgProviderImage = (ImageView) convertView.findViewById(R.id.providerImage); 

      convertView.setTag(viewHolder); 
     } else { 
      /* We recycle a View that already exists */ 
      viewHolder = (ViewHolder) convertView.getTag(); 
     } 

     FilmRecord film = films.get(position); 

     //Get film details from ARRAY and not the database - getting records from a db is time consuming. 
     viewHolder.txtTitle.setText(films.get(position).filmTitle); 
     viewHolder.txtDescription.setText(films.get(position).filmDescription); 
     viewHolder.txtLocations.setText(films.get(position).filmLocations); 
     viewHolder.txtShowingDate.setText("Showing time: " + films.get(position).filmShowingDate); 
     viewHolder.txtAdded.setText("Added on: " + films.get(position).filmAdded); 
     viewHolder.txtProvider.setText(films.get(position).filmProvider); 
     viewHolder.txtTicketUrl.setText(films.get(position).filmTicketUrl); 

     return convertView; 

    } 

} 

幫助這個將是巨大的:)

回答