使用自定义listAdapter进行过滤的ListView
我使用以下代码来使用过滤后的 ListView: 如何在 Android 上动态更新 ListView
我正在尝试将列表视图中的文本颜色设置为黑色。显然这只能通过使用我之前制作的自定义适配器来完成。问题是,如果我切换到自定义适配器,我的 ListView 就不再被正确过滤。有什么想法吗?代码如下:
public class OffCampusStopsAdapter extends ArrayAdapter<String> {
private final Context context;
private final String[] names;
public OffCampusStopsAdapter(Context context, String[] names) {
super(context, R.layout.rowlayout, names);
this.context = context;
this.names = names;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.offcampusstopslayout, null, true);
TextView textView = (TextView) rowView.findViewById(R.id.stoplabel);
textView.setText(names[position]);
String s = names[position];
return rowView;
}
}
Im using the following code to use a filtered ListView:
How to dynamically update a ListView on Android
and am trying to make the text color black in the listview. Apparently this can only be done by using a custom adapter, which I had made before. The problem is if i switch to the custom adapter, my ListView doesnt get properly filtered anymore. any ideas? Heres the code:
public class OffCampusStopsAdapter extends ArrayAdapter<String> {
private final Context context;
private final String[] names;
public OffCampusStopsAdapter(Context context, String[] names) {
super(context, R.layout.rowlayout, names);
this.context = context;
this.names = names;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.offcampusstopslayout, null, true);
TextView textView = (TextView) rowView.findViewById(R.id.stoplabel);
textView.setText(names[position]);
String s = names[position];
return rowView;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我这样做:
I do this way: