mardi 20 octobre 2015

I want to link the NearablesDemoActivity java to the sqlite database, but I couldn't find any help to do this

I'm currently doing a project on shoe sticker using estimote's sticker. What I need to do now is to store the information into the database. Currently I have created the database file, but I have no idea how to link it to the NearablesDemoActivity.java. What I'm doing for NearablesDemoActivity.java is all hard coded. However, after that I have created a database file but I have no idea how to link them together. I'm currently using android studio for my project. For more information of what estimote is you can visit http://ift.tt/1Ghd6kU then relevant codes/help : http://ift.tt/MNNrFS

public class NearablesDemoActivity extends BaseActivity {

private static final String TAG = NearablesDemoActivity.class.getSimpleName();
private Nearable currentNearable;
private BeaconManager beaconManager;
private String scanId;
private Database_nearable db;

TextView Desc, COO, SM, Price;  //description, for Country of origin, for shoe model, for price
Spinner spinnerDropDown;  //for size available
String[] size = {
        "Click to see",
        "5.5'",
        "6'",
        "7'",
        "7.5'",
        "8.5'"
};                   //for size available
Spinner spinnerDropDown2;   //for colours available
String[] colour = {
        "Click to see",
        "Gold",
        "Silver",
        "Copper"
};                      //for colours available
ImageView image1, image2, image3; //For image 1, 2, 3
Button btnRating;  //for button
ArrayList<String> ArrayofNearable = new ArrayList<String>();
List<Nearable> nearables;
static ArrayAdapter<String> dbAdapter;

@Override
protected int getLayoutResId() {
    return R.layout.nearable_demo;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.nearable_demo);

    Desc =(TextView) findViewById(R.id.textview1);   //for description
    // Get reference of SpinnerView from layout/nearable_demo.xml
    spinnerDropDown =(Spinner)findViewById(R.id.spinner1);  //For size available
    spinnerDropDown2 =(Spinner)findViewById(R.id.spinner2);//for colours available
    image1 = (ImageView) findViewById(R.id.shoe1); //display image of shoe
    image2 = (ImageView) findViewById(R.id.shoe1a); //display image of onsale
    image3 = (ImageView) findViewById(R.id.shoe1b); //display image of buy1get1frees
    COO =(TextView) findViewById(R.id.textview2);//for country of origin
    SM =(TextView) findViewById(R.id.textview3); //for shoe model
    Price =(TextView) findViewById(R.id.textview4); //for price
    btnRating = (Button) findViewById(R.id.rd); //for ratingbar

    db = new Database_nearable(this);
    dbAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, ArrayofNearable);


    currentNearable = getIntent().getExtras().getParcelable(ListNearablesActivity.EXTRAS_NEARABLE);
    displayCurrentNearableInfo();

    beaconManager = new BeaconManager(this);

    ArrayAdapter<String> adapter= new ArrayAdapter<>(this,android.R.layout.simple_spinner_dropdown_item ,size);  //for size available
    spinnerDropDown.setAdapter(adapter);
    ArrayAdapter<String> adapter1= new ArrayAdapter<>(this,android.R.layout.simple_spinner_dropdown_item ,colour); //for colours available
    spinnerDropDown2.setAdapter(adapter1);

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setNavigationIcon(R.drawable.ic_action_navigation_arrow_back);
    toolbar.setTitle(getTitle());
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });

    btnRating=(Button)findViewById(R.id.rd);
    btnRating.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent pageforRatingBar = new Intent(getApplicationContext(), RatingBar_main.class);
            startActivity(pageforRatingBar);
        }
    });
}

@Override
protected void onResume() {
    super.onResume();
    beaconManager.setNearableListener(new BeaconManager.NearableListener() {
        @Override
        public void onNearablesDiscovered(List<Nearable> nearables) {
            updateCurrentNearable(nearables);
            displayCurrentNearableInfo();

        }
    });
    beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
        @Override
        public void onServiceReady() {
            scanId = beaconManager.startNearableDiscovery();
        }
    });
}

@Override
protected void onStop() {
    beaconManager.disconnect();
    super.onStop();
}

private void displayCurrentNearableInfo() {
    Desc.setText("The perfect on-point court heels, these classic pumps by KIM&BEN " +
            "flaunt a luxe suedette finish with a sleek silhouette. Chic and sophisticated, " +
            "these lovelies brim with an air of sheer elegance.");
    COO.setText("USA");
    SM.setText("ABXYZ123");
    Price.setText("$99.99");

}

private void updateCurrentNearable(List<Nearable> nearables) {
    for (Nearable nearable : nearables) {
        if (nearable.equals(currentNearable)) {
            currentNearable = nearable;
        }
    }
}
}

Aucun commentaire:

Enregistrer un commentaire