views:

48

answers:

1

I have a program that has items with 3 attributes.

Name(String) : Count(String) : Amount(String)

Currently I am writing the database when someone is trying to access a section then reading from the database. The writing is taking too long.

So my question is how can I perhaps create a nested array where I can say if name = carrot then print carrot['count'] and carrot['amount'].

I am very new to Java so some sample code would be great. Or any other suggestions that you may have as far as tackling this issue.

+1  A: 

Create a bean

package com.storageproj;    

    public class myStorage{

    private String Name;
    private String Count;
    private String Amount;  

    public String getName() {
        return Name;
    }
    public void setName(String Name) {
        this.Name= Name;
    }

        public String getCount() {
        return Count;
    }
    public void setCount(String Count) {
        this.Count= Count;
    }    
        public String getAmount() {
        return Amount;
    }
    public void setAmount(String Amount) {
        this.Amount= Amount;
    }     
}

Import your bean to your main class

import com.storageproj.myStorage;

Then set your data, for example

int Numberofelements = 10;
myStorage = new myStorage[Numberofelements];
for(int i=0;i<Numberofelements;i++){
myStorage [i] = new myStorage ();
myStorage.setName("carrot");
myStorage.setCount("3");
myStorage.setAmount("4");
}

and get the values...

import com.storageproj.myStorage;

myStorage[] myStorage;
        for the first element...
if (myStorage[0].getName == "carrot"){
Toast.makeText(this, "Carrot, Count= " +  myStorage[0].getCount() + ", Amount="+ myStorage[0].getAmount() ,Toast.LENGTH_LONG).show();
}
Jorgesys