我使用适配器在列表中显示了10个不同的值。每个列表都有10个不同的值。如果我只有一个对象在列表中保存不同的值,那么我可以直接使用ArrayAdapter来过滤它。但就我而言,我正在使用不同的对象来显示值。现在我想根据单个值过滤列表。我怎样才能实现这种情况?
这是我的完整代码。
public class CustomEventAdapter extends BaseAdapter implements Filterable{
List<CalEvent> cont;
private CalEvent con;
private EventType event;
private EventStates states;
public static List<Meeting> mlist;
Context ctx;
TextView textView,textView2,textView3,textView4,textView5,textView6,textView7,actualend,meeting_place,meeting_person;
LayoutInflater inflater;
Context context;
public static Meeting meet;
static PendingIntent pendingIntent;
static AlarmManager alarmManager;
Button start_end_meet;
public CustomEventAdapter(Context ctx, List<CalEvent> cont) {
this.ctx = ctx;
this.cont = cont;
inflater = (LayoutInflater) ctx
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return cont.size();
}
@Override
public CalEvent getItem(int position) {
// TODO Auto-generated method stub
return cont.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return cont.get(position).getId();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
if (convertView == null)
rowView = inflater.inflate(R.layout.pd_eve_list_detail, parent,false);
textView = (TextView) rowView.findViewById(R.id.start_Date);
textView2 = (TextView) rowView.findViewById(R.id.actual_start);
textView3 = (TextView) rowView.findViewById(R.id.requirement);
textView4 = (TextView) rowView.findViewById(R.id.pd_event_type);
textView5 = (TextView) rowView.findViewById(R.id.event_state);
textView6 = (TextView) rowView.findViewById(R.id.current_stage);
textView7 = (TextView) rowView.findViewById(R.id.notes);
meeting_place = (TextView) rowView.findViewById(R.id.meeting_place);
meeting_person = (TextView) rowView.findViewById(R.id.meet_person);
con = getItem(position);
event = EventType.getEventType(con.event_type);
states = EventStates.getEventStates(con.event_state);
try {
textView5.setText(states.name);
textView.setText(con.event_start);
textView2.setText(con.actual_start);
textView4.setText(event.name);
textView7.setText(con.notes);
meeting_place.setText(con.followup_location);
meeting_person.setText(con.person_met);
System.out.println(event.name+states.name+con.followup_location);
}catch (Exception e) {
}
return rowView;
}
请帮帮我。提前谢谢。
答案 0 :(得分:0)
我建议你使用这个组件:
https://github.com/matessoftwaresolutions/AndroidFilterableList
此组件允许您以dinamically方式过滤,按对象的属性进行过滤等。
您只需要使用其方法实现两个接口......不再需要。请参阅相关说明。
您还可以找到一个样本,这将使您的实施更加轻松。
给它一个机会!!我希望这会对你有所帮助;)