使用自定义ArrayAdapter你可以“选择”什么是根据一些显示首选项(我会做你传递给构造函数对象的名单上的过滤)。 类似的东西:
public class DbAdapter extends ArrayAdapter<Db> {
private SharedPreferences preferences;
int resource;
String response;
Context context;
//Initialize adapter
public DbAdapter(Context context, int resource, List<Database> items) {
super(context, resource);
this.preferences = PreferenceManager.getDefaultSharedPreferences(context);
filter(items);
this.resource=resource;
}
private final void filter(final List<Database> input) {
final String pref = this.preferences.getString("some_key", "");
for (Database db : input) {
if (!pref.contains(db.dbid + ",")) {
this.add(db);
}
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
LinearLayout DbView;
//Get the current Database object
Database db = this.getItem(position);
// ...
这假定偏好 “some_key” 包含dbId
一个逗号分隔的列表(如1,5,12,
)
NB
嗯,我已经使用了没有经过测试数组适配器为我的listivew生成行。我一直在敲我的头靠在墙上一个星期,现在试图找出如何在我的应用程序中工作。你能详细说明你的答案吗?我对android还是有点新鲜。 – fuzz
你可以添加你的适配器到你的问题?或者给出一个代码链接(pastebin或类似的东西) – 2011-09-05 11:23:14
这里是我的数组和一个辅助类的pastebin链接,用于将json转换为字符串。 http://pastebin.com/yEq7BN3G – fuzz