使用自定義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