サブクラス(セッション)を持つオーバーライドオブジェクトクラス(ガイド)があります。
public class Guide
private class Session
...
ArrayList<Session> sessions;
public ArrayList<Session> getSessionsByTrack(int n) {
ArrayList<Session> tracks = new ArrayList<Session>();
for (Session session : this.sessions) {
if (session.track == n) {
tracks.add(session);
}
}
Collections.sort(tracks); // sort by start and end time.
return tracks;
}
リストを処理して 2 行のリストビューを表示する ListAdapter があります。
public class SessionListAdapter extends BaseAdapter {
private ArrayList<Session> sessions;
//private Session[] sl;
private LayoutInflater mInflater;
public SessionListAdapter(Context context, ArrayList<Session> sl) {
sessions = sl;
mInflater = LayoutInflater.from(context);
}
public int getCount() {
return sessions.size();
}
public Object getItem(int position) {
return sessions.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.session_two_line_list, null);
holder = new ViewHolder();
holder.title = (TextView) convertView.findViewById(R.id.session_title);
holder.time = (TextView) convertView.findViewById(R.id.session_time);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.title.setText(sessions.get(position).getTitle());
holder.time.setText(sessions.get(position).getTimeSpan());
return convertView;
}
static class ViewHolder {
TextView title;
TextView time;
}
}
私の主な活動では、リストアダプターを使用してリストを表示しようとしています:
...
this.lv1 = (ListView) view.findViewById(R.id.SessionListView);
// get sessions
this.sessionList = Guide.getSessionsByTrack(0); // errors here and complains that this method must be static
final SessionListAdapter lv1adapter = new SessionListAdapter(this, this.sessionList);
lv1.setAdapter(lv1adapter);
...
Guide.getSessionsByTrackメソッドの唯一の問題は、そのメソッドが静的である間にthis.sessionsを利用できないことです。sessionListは静的でなければなりません。リストを更新したい場合、これは静的であってはいけませんか?
この小さなしゃっくりは、私を私の目標から遠ざける唯一のものであり、どんな助けも大歓迎です.