0

I had created a spinner activity which is displaying status of work with two options as complete and pending.

Spinner :

public class Coordinator_Status extends Activity implements
AdapterView.OnItemSelectedListener {

String[] status = { "complete", "pending"  };

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.welcome_coordinator);

    Spinner spin = (Spinner) findViewById(R.id.status);
    spin.setOnItemSelectedListener(this);


    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, status);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    spin.setAdapter(dataAdapter);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int position,long id) {
    Toast.makeText(getApplicationContext(),status[position] ,Toast.LENGTH_LONG).show();
}

@Override
public void onNothingSelected(AdapterView<?> arg0) {
    // TODO Auto-generated method stub

}
}

string.xml:

<string name="status_prompt">Status</string>
<string-array name="costatus_array">

    <item>Select Status</item>
    <item>Complete</item>
    <item>Pending</item>        
</string-array>

xml:

<Spinner
    android:id="@+id/status"
    android:layout_width="270dp"
    android:layout_height="50dp"
    android:layout_marginTop="4dp"
    android:layout_gravity="center"
    android:entries="@array/costatus_array"
    android:prompt="@string/status_prompt"
    android:typeface="monospace" />

This is what i had done. Now my question is that if i select pending option, then a pop-up must be displayed which will ask user to select date that when (date) the work will be completed. I hope my question is understandable. Can anyone please help me out?

Girija
  • 15
  • 1
  • have you tried googling? what about [this](http://stackoverflow.com/questions/1337424/android-spinner-get-the-selected-item-change-event) ? instead of a toast show a dialog in `onItemSelected()` – Ayoub Mar 25 '15 at 11:37
  • @Ayoub ya i had searched for the solution but helpless. I had used public void onItemSelected(AdapterView> parent, View arg1, int pos, long arg3) { parent.getItemAtPosition(pos); if (pos == 0) { } else if (pos == 1) { } } what condition i had to provide if pos==1 – Girija Mar 25 '15 at 12:01

1 Answers1

0

From what I understand you basically want to know how to show an AlertDialog.
Here is a way:

AlertDialog.Builder builder = new AlertDialog.Builder(context)
builder.setTitile("title here");
builder.setMessage("message here");
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener () {
    @Override
    public void onClick(DialogInterface dialogInterface, int i) {
        // do something
    }
});
builder.setNegativeButton("Nope", new DialogInterface.OnClickListener () {
    @Override
    public void onClick(DialogInterface dialogInterface, int i) {
        // do something, or dismiss dialog with
        dialogInterface.dismiss();
    }
});
builder.create().show();
Ayoub
  • 341
  • 1
  • 13