2012-02-20 5 views
0

데이터베이스에서 데이터를로드하는 사용자 지정 listview를 만들었습니다. 그런 다음이 데이터를 배열로 가져옵니다.사용자 지정 ListView 스크롤 문제

모든 데이터가 목록보기에서 표시되어야합니다. 그래서 아무런 문제도 없습니다. 내가 겪고있는 문제는 스크롤링입니다. 내가 목록보기를 scoll했을 때 느리게 실행되는 것처럼 보입니다. :)

답변

0

아마이 당신에게 도움이 될 것입니다

이에
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; 

    } 

} 

도움이 좋을 것 : example from the API demos

다음

내 코드의 추출물
관련 문제