Browse files

need to fix Spinner handling in Profiles

  • Loading branch information...
1 parent de07780 commit fe2b51d3e5f10d0b33ee96a5bf7e692c8f184f27 @Kagetsuki Kagetsuki committed Apr 17, 2012
View
2 AndroidManifest.xml
@@ -27,7 +27,7 @@
</activity>
<activity
- android:name="profiles.ProfileSettingsActivity"
+ android:name=".profiles.ProfileSettingsActivity"
android:label="@string/settings" >
</activity>
View
7 src/org/genshin/warehouse/WarehouseActivity.java
@@ -59,17 +59,18 @@ private void loadProfiles() {
profiles = new Profiles(this);
//put profiles in list
- ArrayAdapter<String> profileSpinnerAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
+ /*ArrayAdapter<String> profileSpinnerAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
profileSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
for (int i = 0; i < profiles.list.size(); i++) {
profileSpinnerAdapter.add(profiles.list.get(i).user + ":" + profiles.list.get(i).server);
- }
+ }*/
+ profileSpinner = profiles.attachToSpinner(profileSpinner);
//select default/previous profile
//TODO
//setup listener for list spinner
- profileSpinner.setAdapter(profileSpinnerAdapter);
+ //profileSpinner.setAdapter(profileSpinnerAdapter);
}
private void hookupInterface() {
View
2 src/org/genshin/warehouse/profiles/ProfileSettingsActivity.java
@@ -31,6 +31,7 @@
EditText user;
EditText password;
+ //hooks up interface elements to callbacks and events
private void hookupInterface() {
profiles.attachToSpinner(spinner);
@@ -76,6 +77,7 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.profile_settings);
initViewElements();
+ profiles = new Profiles(this);
hookupInterface();
}
View
37 src/org/genshin/warehouse/profiles/Profiles.java
@@ -17,7 +17,10 @@
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
+import android.view.View;
+import android.widget.AdapterView;
import android.widget.ArrayAdapter;
+import android.widget.Spinner;
public class Profiles {
private SQLiteDatabase db;
@@ -73,13 +76,6 @@ public Profile createProfile(String server, String user, String password) {
return newProfile;
}
- //Delete the specified profile
- public void deleteProfile(Profile profile) {
- openDB();
- db.delete(ProfileDBHelper.TABLE_PROFILES, ProfileDBHelper.COLUMN_ID + " = " + profile.id, null);
- closeDB();
- }
-
//Update a profile
//The profile ID is held within the profile object
public void updateProfile(Profile profile) {
@@ -120,21 +116,33 @@ private Profile cursorToProfile(Cursor c) {
return list;
}
- private void selectProfile(int position) {
+ public void selectProfile(int position) {
if (position < 0 || position >= list.size())
return; //OOB
selectedProfilePosition = position;
selected = list.get(position);
}
- public void deleteSelectedProfile() {
- //TODO profiles.deleteProfile(profiles.list.get(selectedProfile));
+ //Delete the specified profile
+ public void deleteProfile(Profile profile) {
+ openDB();
+ db.delete(ProfileDBHelper.TABLE_PROFILES, ProfileDBHelper.COLUMN_ID + " = " + profile.id, null);
+ closeDB();
}
- public void attachToSpinner(Spinner spinner) {
- spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ //Deletes profile at the specified position in "list"
+ public void deleteProfile(int position) {
+ deleteProfile(list.get(position));
+ }
+ //Deletes the currently selected profile
+ public void deleteSelectedProfile() {
+ deleteProfile(selected);
+ }
+
+ public Spinner attachToSpinner(Spinner spinner) {
+ AdapterView.OnItemSelectedListener selected = new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
//Spinner spinner = (Spinner)parent;
@@ -145,7 +153,10 @@ public void onItemSelected(AdapterView<?> parent, View view,
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
- });
+ };
+
+ spinner.setOnItemSelectedListener(selected);
+ return spinner;
}
public ArrayAdapter<String> getArrayAdapter() {

0 comments on commit fe2b51d

Please sign in to comment.