i have a spinner with 4 value
String[] petak = { "Petak 1", "Petak 2", "Petak 3", "Petak 4" };
First i choose the value "Petak 1"
then i choose "foto dan save" to next step
and the value now is
because value "Petak 1" is already choosen before, so the value "Petak 1" is dissapear.
now i choose "foto dan save" again
and the value is
because value "Petak 1" and "Petak 2" is already choosen before, so the value "Petak 1" and "Petak 2" is dissapear.
The question is how to manipulate value spinner when i choose the value Random , Example : i choose "Petak 2" First ? so the value is show "Petak 1", "Petak 3", "Petak 4"
here is my code
View spinner1 = (Spinner) findViewById(R.id.namapetak);
String spinnerPetak=((Spinner) spinner1).getSelectedItem().toString();
if (spinnerPetak == "Petak 1"){
String[] petak1 = { "Petak 2", "Petak 3", "Petak 4" };
// buat spinner manual manufaktur
Spinner spin3 = (Spinner) findViewById(R.id.namapetak);
//spin3.setOnItemSelectedListener(this);
ArrayAdapter<String> aa = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, petak1);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin3.setAdapter(aa);
//update = (Button) findViewById(R.id.update);
spin3 = (Spinner) findViewById(R.id.namapetak);
spin3.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
//Toast.makeText(CPupukApp.this, "Anda Memilih: " + manufaktur[position],Toast.LENGTH_LONG).show();
}
public void onNothingSelected(AdapterView<?> parent) {
}
});
View b = findViewById(R.id.btnPupukQuit);
b.setVisibility(View.GONE);
onBackPressed();
onAttachedToWindow();
}
if (spinnerPetak == "Petak 2"){
String[] petak1 = { "Petak 3", "Petak 4" };
// buat spinner manual manufaktur
Spinner spin3 = (Spinner) findViewById(R.id.namapetak);
//spin3.setOnItemSelectedListener(this);
ArrayAdapter<String> aa = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, petak1);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin3.setAdapter(aa);
//update = (Button) findViewById(R.id.update);
spin3 = (Spinner) findViewById(R.id.namapetak);
spin3.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
//Toast.makeText(CPupukApp.this, "Anda Memilih: " + manufaktur[position],Toast.LENGTH_LONG).show();
}
public void onNothingSelected(AdapterView<?> parent) {
}
});
View b = findViewById(R.id.btnPupukQuit);
b.setVisibility(View.GONE);
onBackPressed();
onAttachedToWindow();
}
if (spinnerPetak == "Petak 3"){
String[] petak1 = { "Petak 4" };
// buat spinner manual manufaktur
Spinner spin3 = (Spinner) findViewById(R.id.namapetak);
//spin3.setOnItemSelectedListener(this);
ArrayAdapter<String> aa = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, petak1);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin3.setAdapter(aa);
//update = (Button) findViewById(R.id.update);
spin3 = (Spinner) findViewById(R.id.namapetak);
spin3.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
//Toast.makeText(CPupukApp.this, "Anda Memilih: " + manufaktur[position],Toast.LENGTH_LONG).show();
}
public void onNothingSelected(AdapterView<?> parent) {
}
});
View b = findViewById(R.id.btnPupukQuit);
b.setVisibility(View.GONE);
onBackPressed();
onAttachedToWindow();
}
Anyone help me?
EDIT
this code work when i put this on button onClick "Foto dan Save", but error when i put to onActivityResult , line switch (v.getId())
can switch
add in onActivityResult?
String myData = toList.getSelectedItem().toString();
int position = dataAdapter.getPosition(myData);
switch (View.getId()) {
case R.id.btnPetakFoto:
if(position >= 0){
dataAdapter.remove(myData);
dataAdapter.notifyDataSetChanged();
}
else {
Toast.makeText(getBaseContext(), myData + " not in Spinner", Toast.LENGTH_LONG).show();
}
break;
// More buttons go here (if any) ...
}
View b = findViewById(R.id.btnPupukQuit);
b.setVisibility(View.GONE);
onBackPressed();
onAttachedToWindow();