0
ここではこの件に関する記事が失われていますが、私の状況では誰も助けてくれませんでした。 私は、名前、ナブマー、アパート番号を持つショッピングカートの項目の配列を持っています。 と私は、この配列を受け取り、スピナーに移入するためのアダプタを持っています。位置0のカスタムアダプターでスピナーのデフォルメ値を設定する
これはアダプタです:
public class SpinnerAdapter extends BaseAdapter {
ArrayList<ShopCartModel> list;
Context context;
LayoutInflater inflater;
public SpinnerAdapter(Context c, ArrayList<ShopCartModel> list) {
this.context = c;
this.list = list;
inflater = (LayoutInflater.from(c));
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = inflater.inflate(R.layout.custom_spinner_item, null);
TextView name = (TextView) convertView.findViewById(R.id.textView);
ShopCartModel tmp = list.get(position);
name.setText(tmp.getName());
return convertView;
}
}
これが私のメインです:
public class ShopCartScreen extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
Spinner spin;
ArrayList<ShopCartModel> shopCarts;
SpinnerAdapter spinnerAdapter;
GetShopLists getShopList;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.shop_carts_list);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
cartItems = (RecyclerView) findViewById(R.id.newListItem);
spin = new Spinner(ShopCartScreen.this);
db = DBHelper.getInstance(this);
int apartmentNumber = preferences.getInt("apartmentNumber", 0);
apartment = new ApartmentModel(apartmentNumber);
getShopList = new GetShopLists(this, shopCarts, spin, spinnerAdapter);
getShopList.execute("link to the query");
toolbar.addView(spin, 0);
spin.setOnItemSelectedListener(this);
}
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
preferences = getSharedPreferences("appData", 0);
boolean flag = preferences.getBoolean("ItemsLoadedFromDb", false);
ShopCartModel tmp = shopCarts.get(position);
getShopingCartList = new GetShopingCartList(this, list, adapter, cartItems, tmp.getNumber());
getShopingCartList.execute("link to the query");
}
しかし、アイテムが数えることを覚えて、今大きいです:はlist.size() + HINT_COUNT –