Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6528279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:31:11+00:00 2026-05-25T09:31:11+00:00

I am implementing a database where each item (plant) has a gallery of images.

  • 0

I am implementing a database where each item (plant) has a gallery of images. For each plant in the database I create a folder to store the image.

When I view an item I want its details to be displayed along with the gallery of images however the section where the gallery should be is blank.

I am not sure if my xml or code is to blame so here is the xml…

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content">

        <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:stretchColumns="*">

              ...Content Removed...

        </TableLayout>

        <Gallery xmlns:android="http://schemas.android.com/apk/res/android"
                 android:id="@+id/plant_gallery"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content" />

    </LinearLayout>    
</ScrollView>

…and the code…

public class Plant extends Activity
{
    private PlantDatabase pDatabase;
    Cursor plantC;

    private boolean mExternalStorageAvailable = false;
    private boolean mExternalStorageWriteable = false;
    private String state;
    File plantDir;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.plant);

        Bundle b = getIntent().getExtras();
        String plantID = b.getString("id");

        state = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(state))
        {
            // We can read and write
            mExternalStorageAvailable = mExternalStorageWriteable = true;
        }
        else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state))
        {
            // We can only read
            mExternalStorageAvailable = true;
            mExternalStorageWriteable = false;
        }
        else
        {
            // We have no access
            mExternalStorageAvailable = mExternalStorageWriteable = false;
        }

        if (mExternalStorageAvailable)
        {
            plantDir = new File(Environment.getExternalStorageDirectory() + "/PlantLog/" + plantID);

            if (!plantDir.exists())
            {
                if (mExternalStorageWriteable)
                {   
                    if (!plantDir.mkdirs())
                    {
                        Toast.makeText(this, "Unable to make image directory for current plant", Toast.LENGTH_LONG).show();
                    }
                }
            }

            plantDir = new File(Environment.getExternalStorageDirectory() + "/PlantLog/" + plantID);

            if (plantDir.exists())
            {
                Gallery g = (Gallery)findViewById(R.id.plant_gallery);
                g.setAdapter(new ImageAdapter(this, getImageList(plantID)));

                g.setOnItemClickListener(new OnItemClickListener()
                {
                    public void onItemClick(AdapterView<?> parent, View v, 
                                            int position, long id)
                    {

                    }
                });
            }
        }

        pDatabase = new PlantDatabase(this);
        plantC = pDatabase.getPlant(plantID);

        plantC.moveToFirst();

        TextView t;

        // Display results
        t = (TextView)findViewById(R.id.plant_dbid);
        t.setText(plantC.getString(0));

        t = (TextView)findViewById(R.id.plant_plantid);
        t.setText(plantC.getString(1));

        t = (TextView)findViewById(R.id.plant_commonname);
        t.setText(plantC.getString(2));

        t = (TextView)findViewById(R.id.plant_family);
        t.setText(plantC.getString(3));

        t = (TextView)findViewById(R.id.plant_genus);
        t.setText(plantC.getString(4));

        t = (TextView)findViewById(R.id.plant_species);
        t.setText(plantC.getString(5));

        t = (TextView)findViewById(R.id.plant_variety);
        t.setText(plantC.getString(6));

        t = (TextView)findViewById(R.id.plant_form);
        t.setText(plantC.getString(7));

        t = (TextView)findViewById(R.id.plant_cultivar);
        t.setText(plantC.getString(8));

        t = (TextView)findViewById(R.id.plant_synonyms);
        t.setText(plantC.getString(9));

        t = (TextView)findViewById(R.id.plant_flowercolour);
        t.setText(plantC.getString(10));

        t = (TextView)findViewById(R.id.plant_datesown);
        t.setText(plantC.getString(11));

        t = (TextView)findViewById(R.id.plant_dateacquired);
        t.setText(plantC.getString(12));

        t = (TextView)findViewById(R.id.plant_pricepaid);
        t.setText(plantC.getString(13));

        t = (TextView)findViewById(R.id.plant_growingnotes);
        t.setText(plantC.getString(14));
    }

    private List<String> getImageList(String dir)
    {
        List<String> tFileList = new ArrayList<String>();

        File f = new File(Environment.getExternalStorageDirectory() + "/PlantLog/" + dir);      
        File[] files = f.listFiles();

        for (int i = 0; i < files.length; i++)
        {
            File file = files[i];

            // Check file is jpg image
            if (file.getPath().endsWith(".jpg"))
            {
                tFileList.add(file.getPath());
            }
        }

        return tFileList;
    }

    public class ImageAdapter extends BaseAdapter
    {
        private Context mContext;
        private List<String> fileList;
        private ImageView i;
        private int mGalleryItemBackground;

        public ImageAdapter(Context c, List<String> fList)
        {
            mContext = c;
            fileList = fList;
            i = new ImageView(mContext);

            TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
            mGalleryItemBackground = a.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 0);
            a.recycle();
        }

        public int getCount()
        {
            return fileList.size();
        }

        public Object getItem(int position)
        {
            return position;
        }

        public long getItemId(int position)
        {
            return position;
        }

        public View getView(int position, View convertView,
                            ViewGroup parent)
        {
            System.gc();

            if (convertView == null)
            {
                try
                {
                    Bitmap bm = BitmapFactory.decodeFile(fileList.get(position).toString());

                    i.setImageBitmap(bm);
                    i.setLayoutParams(new Gallery.LayoutParams(150, 100));
                    i.setScaleType(ImageView.ScaleType.FIT_XY);
                    i.setBackgroundResource(mGalleryItemBackground);
                }
                catch (Exception e)
                {
                    // Nothing to see here
                }
            }

            return i;
        }
    }
}

Sorry it is so long but hopefully I have included enough. The gallery was mostly based on the Gallery example but tweaked to match my code. If anyone has any idea why the images are not displayed I would appreciate the help!

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T09:31:12+00:00Added an answer on May 25, 2026 at 9:31 am

    Default LinearLayout orientation is horizontal 🙂

    (Edit:What I mean is, check that it isn’t off the RHS of your activity)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm implementing a service where each user must have his own json/document database. Beyond
I know implementing database is a huge topic, but I want to have a
I am implementing a push notification service. I would need to create a database
Have/Want List Matching Algorithm I am implementing an item trading system on a high-traffic
I am implementing a Database for my (beginner/Android) application. It is not clear to
I am implementing a database application and I will use both JavaDB and MySQL
I am implementing a small database(university Project) and i am facing the following problem.
I have to choose a database for implementing a sharing system. My system will
I'm implementing my own Content Provider because I'm gonna synchronize my database with a
I am implementing an application using ember.js and couchdb. I choose ember-resource as database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.