2016-03-22 11 views
0

いくつかの属性を持つ静的クラスがありますが、クラスは静的ですが、静的ではないというエラーが表示されます。静的コンテキストから非静的フィールドを参照することはできません

私は解決策を見つけることができません。見ている例は非常に似ています。ビューホルダーは常に静的またはのpublic staticとして内部アダプタです。ここ

は私ArrayAdapterです:

ここ
public class NoteAdapter extends ArrayAdapter<Note> { 

public static class ViewHolder{ 
    TextView noteTitle; 
    TextView noteBody; 
    ImageView noteIcon; 
} 

public NoteAdapter(Context context, ArrayList<Note> notes) { 
    super(context, 0, notes); 
} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
    Note note = getItem(position); 
    ViewHolder viewHolder; 

    if (convertView == null) { 
     viewHolder = new ViewHolder(); 
     convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_row, parent, false); 

     // == Here I am getting the error == 
     ViewHolder.noteTitle = (TextView) convertView.findViewById(R.id.text_item_note_title); 
     ViewHolder.noteBody = (TextView) convertView.findViewById(R.id.text_item_note_body); 
     ViewHolder.noteIcon = (ImageView) convertView.findViewById(R.id.image_item_note); 

     convertView.setTag(viewHolder); 
    } 

    return convertView; 
} 

}

私のノートモデルです:

public class Note { 
    private String title, message; 
    private long noteId, dateCreateMilli; 
    private Category category; 

    public enum Category {PERSONAL, TECHNICAL, QUOTE, FINANCE} 

    public Note(String title, String message, Category category) { 
     this.title = title; 
     this.message = message; 
     this.category = category; 
     this.noteId = 0; 
     this.dateCreateMilli = 0; 
    } 

    public Note(String title, String message, Category category, long noteId, long dateCreateMilli) { 
     this.title = title; 
     this.message = message; 
     this.category = category; 
     this.noteId = noteId; 
     this.dateCreateMilli = dateCreateMilli; 
    } 

    public String getTitle() { 
     return this.title; 
    } 

    public String getMessage() { 
     return this.message; 
    } 

    public long getNoteId() { 
     return this.noteId; 
    } 

    public long getDateCreateMilli() { 
     return this.dateCreateMilli; 
    } 

    public Category getCategory() { 
     return this.category; 
    } 

    public TextDrawable getIconResource() { 
     return TextDrawable.builder().buildRound("P", android.R.color.darker_gray); 
    } 
} 

私はあなたの助けに感謝します。前もって感謝します。

答えて

5
ViewHolder.noteTitle = (TextView) convertView.findViewById(R.id.text_item_note_title); 
    ViewHolder.noteBody = (TextView) convertView.findViewById(R.id.text_item_note_body); 
    ViewHolder.noteIcon = (ImageView) convertView.findViewById(R.id.image_item_note); 

ViewHolderクラスの名前です。インスタンスの名前はviewHolder(小文字の最初の文字)です。フィールドnoteTitleなどはインスタンスメンバーであり、インスタンス(つまりviewHolder)への参照を参照する必要があります。

関連する問題