2013-12-23 6 views
1

안녕하세요 저는 사용자 정의 배열 어댑터를 만들었습니다. 응용 프로그램을 실행할 때 충돌을 일으키지 않지만 아무 일도 일어나지 않습니다. 어댑터에서 로그를 구현하려고 시도했지만 스틱은 어느 부분인지 보지 못했습니다. 그것은 그것의 무엇이든을 달리지 않는가? 누구나 A. 내가 뭘 잘못하고 있는지 또는 B. 맞춤형 배열 어댑터를 올바르게 구현하는 방법을 알고 있습니까?안드로이드 사용자 정의 배열 어댑터가 실행되지 않습니다

을 heres 내 어댑터

import java.util.ArrayList; 

import android.content.ClipData.Item; 
import android.content.Context; 
import android.util.Log; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.ArrayAdapter; 
import android.widget.ImageView; 
import android.widget.TextView; 

public class DocumentArrayAdapter extends ArrayAdapter<String> { 



    // declaring our ArrayList of items 
    private ArrayList<String> docTitles; 
    private ArrayList<String> docTypes; 
    private ArrayList<String> docModified; 
    /* here we must override the constructor for ArrayAdapter 
    * the only variable we care about now is ArrayList<Item> objects, 
    * because it is the list of objects we want to display. 
    */ 
    public DocumentArrayAdapter(Context context, int layoutResourceId, ArrayList<String> docTitles, ArrayList<String> docTypes, ArrayList<String> docModified) { 
     super(context, layoutResourceId); 
     this.docTitles = docTitles; 
     this.docTypes = docTypes; 
     this.docModified = docModified; 

    } 

    /* 
    * we are overriding the getView method here - this is what defines how each 
    * list item will look. 
    */ 
    public View getView(int position, View convertView, ViewGroup parent){ 

     // assign the view we are converting to a local variable 
     View v = convertView; 
     Log.v("Main","v, = " + v); 
     // first check to see if the view is null. if so, we have to inflate it. 
     // to inflate it basically means to render, or show, the view. 
     if (v == null) { 
      LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      v = inflater.inflate(R.layout.document_cell, null); 
     } 

     /* 
     * Recall that the variable position is sent in as an argument to this method. 
     * The variable simply refers to the position of the current object in the list. (The ArrayAdapter 
     * iterates through the list we sent it) 
     * 
     * Therefore, i refers to the current Item object. 
     */ 
     String title = docTitles.get(position); 
     String types = docTypes.get(position); 
     String modified = docModified.get(position); 

     Log.v("Main","DocumentArrayAdapter, = " + title + " " + types + " " + modified); 

     if (title != null) { 

      // This is how you obtain a reference to the TextViews. 
      // These TextViews are created in the XML files we defined. 

      TextView docTitle = (TextView) v.findViewById(R.id.name); 
      TextView docType = (TextView) v.findViewById(R.id.doctype); 
      TextView docMod = (TextView) v.findViewById(R.id.modified); 
      ImageView docImage = (ImageView) v.findViewById(R.id.docicon); 


      // check to see if each individual textview is null. 
      // if not, assign some text! 
      if (docTitle != null){ 
       docTitle.setText(title); 
      } 
      if (docTypes != null){ 
       docType.setText(types); 
      } 
      if (docTitle != null){ 
       docMod.setText(modified); 
      } 


     } 

     // the view must be returned to our activity 
     return v; 

    }} 

과를 heres 내가 조각 docNamesArray, DocTypeArray 및 DocModifiedArray 내부를 호출하고있어 모든 Arraylists입니다.

docsList = (ListView) rootView.findViewById(R.id.list); 
    adapter = new DocumentArrayAdapter (getActivity(),R.layout.document_cell, docNamesArray,docTypeArray,docModifiedArray); 
       docsList.setAdapter(adapter); 

답변

2

변경이

super(context, layoutResourceId); 

super(context, layoutResourceId,docTitles); 

에 또한 부드러운 스크롤과 성능에 대한 ViewHolder 패턴을 사용하는 것이 좋습니다. 어댑터 생성자 위해 LayoutInflater = LayoutInflater.from (컨텍스트)에서

http://developer.android.com/training/improving-layouts/smooth-scrolling.html

+0

감사이리스트 뷰는 뷰를 재활용 방법은 관심이를 확인할 경우 홀더 –

+0

@LukeBatley에 대해 너무 대접 좋은 조언을했다. http://stackoverflow.com/questions/11945563/how-listviews-recycling-mechanism-works. 사이트에서 허용하는 경우 대답을 수락하십시오. – Raghunandan

0

;

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

if (convertView == null) { 

       convertView = layoutInflater.inflate(R.layout.activitylayout, 
         null); 

holder = new ViewHolder(); 

       holder.tt = (TextView) convertView.findViewById(R.id.toptext); 




}else { 

       holder = (ViewHolder) convertView.getTag(); 
      } 



holder.tt.setText(text); 

return convertView; 

} 
관련 문제