// Allows for code reuse private void setLayoutMain() { Log.d(TAG, "Layout is main"); setContentView(R.layout.snet_main); SNetDB461 database = null; // Attempts to set the my and chosenPhoto displays try { database = new SNetDB461(pathName + "/" + mMyName + "snet.db"); CommunityRecord me = database.COMMUNITYTABLE.readOne(mMyName.toString()); PhotoRecord myPhoto = database.PHOTOTABLE.readOne(me.myPhotoHash); PhotoRecord chosenPhoto = database.PHOTOTABLE.readOne(me.chosenPhotoHash); if (myPhoto == null) { Log.w(TAG, "Photo record for myPhoto is null"); } else { ((ImageView) findViewById(R.id.mypicture)) .setImageBitmap(BitmapLoader.loadBitmap(myPhoto.file.getCanonicalPath(), 100, 100)); } if (chosenPhoto == null) { Log.w(TAG, "Photo record for chosenPhoto is null"); } else { ((ImageView) findViewById(R.id.chosenpicture)) .setImageBitmap(BitmapLoader.loadBitmap(chosenPhoto.file.getCanonicalPath(), 100, 100)); } } catch (DB461Exception e) { Log.e(TAG, "Had trouble with the database"); } catch (IOException e) { Log.e(TAG, "Couldn't get the filename for the photos to work"); } finally { if (database != null) { database.discard(); } } }
// Allows for code reuse private void setLayoutContact() { setContentView(R.layout.snet_contact); currentLayout = R.layout.snet_contact; List<CharSequence> names = new ArrayList<CharSequence>(); try { SNetDB461 database = new SNetDB461(pathName + "/" + mMyName + "snet.db"); RecordSet<CommunityRecord> records = database.COMMUNITYTABLE.readAll(); for (CommunityRecord rec : records) { names.add(rec.name.toString()); } // Populates the list of names with those included in the community database.discard(); } catch (DB461Exception e) { Log.e(TAG, "Failed to access the database"); } // Sets up the spinner Spinner spinner = (Spinner) findViewById(R.id.memberspinner); ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item, names); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(this); Log.d(TAG, "Setting the spinner"); }