简体   繁体   中英

Image Display not showing in Custom Spinner Adapter

i am using following code to attach an image placed in my asset Folder

  ArrayAdapter<CharSequence> adapter = new CustomArrayAdapterForCurrencies(this, currenciesDataSource.keys);
      paidIn.setAdapter(adapter);


viewHolder.flag = (ImageView) view.findViewById(R.id.UICurrencyCurrencyFlag);
            String filename = "Images/Currencies/" + keys[position] + ".png";
            try {
                InputStream bitmap= context.getResources().getAssets().open(filename);
                Bitmap bit=BitmapFactory.decodeStream(bitmap);
                viewHolder.flag.setImageBitmap(bit);
            } catch (IOException e1) {
                e1.printStackTrace();
            }

有图像

But when i click on Spinner following this happens, If i click on let us say , INR, The indian flag shows up just like above, but i want all the flags to be shown in this screen too.

没有图像

Please tell me what is the problem Best Regards

If PaidIn is a spinner ,then you must have set a DropDownViewResource layout file for it using setDropDownViewResource() . Use a custom layout file with an imageview and textview as your drop down resource, then you will be able to shown Indian and other flag images too... For example:

Spinner spin = (Spinner) findViewById(R.id.spinner);
        spin.setOnItemSelectedListener(this);

        ArrayAdapter aa = new ArrayAdapter(
                this,
                android.R.layout.simple_spinner_item, 
                items);

        aa.setDropDownViewResource(
           android.R.layout.simple_spinner_dropdown_item);
        spin.setAdapter(aa);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM