Ik ben wat aan het experimenteren met een voorbeeldcode die ik gedownload heb en probeer dit aan te passen naar wat ik nodig heb.
De toepassing zoals ze nu is bestaat uit 5 velden die een record maken en opgeslagen wordt in een SQLite database.
Momenteel worden de waarden allemaal via EditText manueel ingegeven.
Ik probeer nu in één veld dit te doen via een Spinner.
Van het derde veld met ID etKleurwaaier zou ik een Spinner willen maken. De waarde die uiteindelijk geselecteerd wordt dient mee opgeslagen te worden in de database.
Kan iemand mij hiermee op weg helpen. Ik vind op internet wel voorbeelden terug van de code van Spinners maar voorlopig is mijn kennis te beperkt om dit geïntegreerd te krijgen in mijn toepassing.
Ik plaats hierbij alvast een deel van de code die ik momenteel heb.
table_manipulation.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="https://schemas.android.com/apk/res/android"
xmlns:tools="https://schemas.android.com/tools"
android:id="@+id/layoutAddUpdate"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="@+id/etLocatie"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Locatie"
android:inputType="textCapWords" />
<EditText
android:id="@+id/etProduct"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Product"
android:inputType="textCapWords" />
<EditText
android:id="@+id/etKleurwaaier"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Kleurwaaier"
android:inputType="textCapWords" />
<EditText
android:id="@+id/etKleur"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Kleur"
android:inputType="textCapWords" />
<EditText
android:id="@+id/etInhoud"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Inhoud"
android:inputType="textCapWords" />
<com.rey.material.widget.Button
android:id="@+id/btnDML"
style="@style/RaiseWaveColorButtonRippleStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_blue"
android:text="Bewaar"
android:textColor="@color/color_white"
android:textStyle="bold"
/>
</LinearLayout>
TableManipulationActivity.java
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class TableManipulationActivity extends Activity {
EditText etLocatie;
EditText etProduct;
EditText etKleur;
EditText etKleurwaaier;
EditText etInhoud;
Button btnDML;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.table_manipulation);
getAllWidgets();
bindWidgetsWithEvent();
checkForRequest();
}
private void checkForRequest() {
String request = getIntent().getExtras().get(Constants.DML_TYPE).toString();
if (request.equals(Constants.UPDATE)) {
btnDML.setText(Constants.UPDATE);
etLocatie.setText(getIntent().getExtras().get(Constants.LOCATIE).toString());
etProduct.setText(getIntent().getExtras().get(Constants.PRODUCT).toString());
etKleurwaaier.setText(getIntent().getExtras().get(Constants.KLEURWAAIER).toString());
etKleur.setText(getIntent().getExtras().get(Constants.KLEUR).toString());
etInhoud.setText(getIntent().getExtras().get(Constants.INHOUD).toString());
} else {
btnDML.setText(Constants.INSERT);
}
}
private void bindWidgetsWithEvent() {
btnDML.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onButtonClick();
}
});
}
private void getAllWidgets() {
etLocatie = (EditText) findViewById(R.id.etLocatie);
etProduct = (EditText) findViewById(R.id.etProduct);
etKleurwaaier = (EditText) findViewById(R.id.etKleurwaaier);
etKleur = (EditText) findViewById(R.id.etKleur);
etInhoud = (EditText) findViewById(R.id.etInhoud);
btnDML = (Button) findViewById(R.id.btnDML);
}
private void onButtonClick() {
if (etLocatie.getText().toString().equals("") || etProduct.getText().toString().equals("") || etKleurwaaier.getText().toString().equals("") || etKleur.getText().toString().equals("") || etInhoud.getText().toString().equals("")) {
Toast.makeText(getApplicationContext(), "Add Both Fields", Toast.LENGTH_LONG).show();
} else {
Intent intent = new Intent();
intent.putExtra(Constants.LOCATIE, etLocatie.getText().toString());
intent.putExtra(Constants.PRODUCT, etProduct.getText().toString());
intent.putExtra(Constants.KLEURWAAIER, etKleurwaaier.getText().toString());
intent.putExtra(Constants.KLEUR, etKleur.getText().toString());
intent.putExtra(Constants.INHOUD, etInhoud.getText().toString());
setResult(RESULT_OK, intent);
finish();
}
}
}