Hello,

I have this question. I created a small program with which you can add x.Job and save to the Database. In the program 4. components: EditTech (ADD_Task), Spinner / Drop down and EditText_description.
Data storage works. The problem is that I add Tasks 1 to EditText before I save it (with add_button) I write a description to Task 1 in the lower EditText_description to Task 1 (each task has a description). Below I write a description of it (despription should not seem to drop down). Clicking on Button Add saves Tasks 1. and its Description to the Database. I can't correctly write a function where data is loaded from Sqlite to drop down. At the moment, in the drop down load and rear and description.

enter image description here

Who could help me deal with the problem? Need to fix the code probably another question. In EditText_output the description should appear. Only when I select task 2. Go to task 2. I should see descriptions for it in EditText_output. For example. I choose task 3 in drop down. I chose tasks as soon as I selected descriptions for it in EditText_output (description 3.)

spasibo

enter image description here

DataBaseHandler.java

public void insertLabel(String label) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_NAME, label); values.put(KEY_DESCR, label); // Inserting Row db.insert(TABLE_LABELS, null, values); db.close(); // Closing database connection } public void deleteLabel(String l) { SQLiteDatabase db = this.getWritableDatabase(); db.delete(DATABASE_NAME, KEY_NAME + "=?", new String[] { l }); } /** * Getting all labels returns list of labels */ public List<String> getLabels() { List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "SELECT * FROM " + TABLE_LABELS; // String selectQuery = "SELECT name FROM " + TABLE_LABELS; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor != null) { if (cursor.moveToFirst()) { /* * do { labels.add(cursor.getString(1)); } while * (cursor.moveToNext()); */ for (int i = 0; i < cursor.getCount(); i++) { labels.add(cursor.getString(i)); } // closing connection cursor.close(); db.close(); } } return labels; 

Main.java

  loadSpinnerData(); /** * Add new label button click listener */ btnAdd.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { String label = inputLabel.getText().toString(); String label1 = inputDescription.getText().toString(); if (label.trim().length() > 0) { // database handler DatabaseHandler db = new DatabaseHandler(getApplicationContext()); // inserting new label into database db.insertLabel(label); db.insertLabel(label1); // making input filed text to blank inputLabel.setText(""); inputDescription.setText(""); // Hiding the keyboard InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(inputLabel.getWindowToken(), 0); // loading spinner with newly added data loadSpinnerData(); } else { Toast.makeText(getApplicationContext(), "Please enter label name", Toast.LENGTH_SHORT).show(); } } }); } /** * Function to load the spinner data from SQLite database */ private void loadSpinnerData() { // database handler DatabaseHandler db = new DatabaseHandler(getApplicationContext()); // Spinner Drop down elements List<String> lables = db.getLabels(); // Creating adapter for spinner ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, lables); // Drop down layout style - list view with radio button dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // attaching data adapter to spinner spinner.setAdapter(dataAdapter); } @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { // On selecting a spinner item String label = parent.getItemAtPosition(position).toString(); // Showing selected spinner item Toast.makeText(parent.getContext(), "You selected: " + label, Toast.LENGTH_LONG).show(); // String myState = (String) spinner.getSelectedItem(); // String myStatesCapital = (String) spinner.getSelectedItem(); // // inputLabel.setText(myState); // inputDescription.setText(myState // + myStatesCapital); // inputDescription.setText(label ); } 

    0