我创建了一个微调器活动,它显示工作状态,有两个选项为完成和待定。
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" />
这就是我所做的。 现在我的问题是,如果我选择待定选项,则必须显示弹出窗口,该弹出窗口将要求用户选择何时(日期)工作将完成的日期。我希望我的问题是可以理解的。 有人可以帮帮我吗?
答案 0 :(得分:0)
根据我的理解,您基本上想知道如何展示AlertDialog
这是一种方式:
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();