所以我有一個字符串數組,我有。我正在嘗試將每個單個項目從該字符串數組傳遞給自定義適配器。我無法弄清楚如何使用我在自定義適配器中傳遞的字符串?使用帶有自定義適配器的字符串數組來使用listview?
的String []我通過
String favorites = String.valueOf(FavList.get(0).get("favorites_list"));
String[] separated = favorites.split(",");
for (String s: separated) {
//Do your stuff here
FavoritesAdapter.add(s);
}
Adapter.class
public class FavoritesAdapter extends ArrayAdapter<favoriteList> {
private final Context mContext;
private List<favoriteList> favlist;
private TextView favorites;
private TextView favDetail;
public FavoritesAdapter(Context context, ArrayList<favoriteList> objects) {
super(context, R.layout.favorites_listview_single, objects);
this.mContext = context;
this.favlist = objects;
}
public View getView(final int position, View convertView, final ViewGroup parent) {
if (convertView == null) {
LayoutInflater mLayoutInflater = LayoutInflater.from(mContext);
convertView = mLayoutInflater.inflate(R.layout.favorites_listview_single, null);
}
// Here is where i cant figure out how to get the string that I passed.
return convertView;
}
}
爲您的數據創建一個ArrayList,然後將它傳遞給您的適配器。沒有看到你的適配器代碼,很難知道 – Eenvincible
對不起,忘了添加,剛剛添加。 – AndroidDev21921