I'm currently having a problem when I try to use the AlertDialog.setView(View v)
function.
When the dialog is rendered, no matter the theme used, it generates a border around the layout, just as if another layout was encapsulating it.
Using builder.show()
alone, builder.create()
alone or both together yields the same results.
Am I missing something somewhere, or is it a known bug ? Thanks in advance if you can help.
dialog_status.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Spinner
android:id="@+id/spinnerStatus"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/editTextStatus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Status"
android:inputType="textMultiLine"/>
<CheckBox
android:id="@+id/checkBoxStatus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="@string/save_status"/>
</LinearLayout>
Code inside Activity :
private void showStatusDialog(){
AlertDialog.Builder builder = new AlertDialog.Builder(this, android.R.style.Theme_Holo_Dialog);
//AlertDialog.Builder builder = new AlertDialog.Builder(this); (Yields the same results, just another theme)
View root = View.inflate(this, R.layout.dialog_status, null);
final EditText input = (EditText) root.findViewById(R.id.editTextStatus);
final Spinner spinner = (Spinner) root.findViewById(R.id.spinnerStatus);
final CheckBox checkBox = (CheckBox) root.findViewById(R.id.checkBoxStatus);
final Preferences p = new Preferences(FChatActivity.this);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
input.setText(p.getDefaultStatusMessage(FCharacter.Status.getIdentifiers().get(i)));
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item);
adapter.addAll(FCharacter.Status.getLabels());
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
spinner.setAdapter(adapter);
builder.setView(root)
.setMessage("Update your status")
.setTitle("Status")
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
setStatus(FCharacter.Status.getIdentifiers().get(spinner.getSelectedItemPosition()),input.getText().toString(), checkBox.isChecked());
dialogInterface.dismiss();
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
builder.create();
builder.show();
}
Screenshots :