我有一個AlertDialog中的兩個微調,spinners看起來不錯,並且項目列表是正確的,它顯示每個列表的第一項。但是,當我點擊兩個微調框中的任何一個時,下拉列表不會顯示爲選擇其他項目。紡紗工什麼都不做。當我是AlertDialog之外的兩個相同的旋轉器時,不會發生這種情況。無法顯示AlertDialog中的微調DropDown列表 - Android
這是AlertDialog的代碼:爲紡紗
private void mostrar_alertdialog_spinners() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
TextView title = new TextView(this);
title.setText("Selecciona un archivo:");
title.setPadding(10, 10, 10, 10);
title.setGravity(Gravity.CENTER);
title.setTextColor(Color.rgb(0, 153, 204));
title.setTextSize(23);
builder.setCustomTitle(title);
LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout_spinners = inflater.inflate(R.layout.layout_spinners,null);
sp_titulos_carpetas = (Spinner) layout_spinners.findViewById(R.id.spinner_titulo_carpetas);
sp_titulos_textos = (Spinner) layout_spinners.findViewById(R.id.spinner_textos_carpetas);
builder.setView(layout_spinners);
builder.setCancelable(false);
builder.show();
//configuracion de textos en memoria sd
String path = Environment.getExternalStorageDirectory().toString()+"/Textos/";
File f = new File(path);
String[] fileStr = f.list();
ArrayList<String> lista_lista_CARPETAS = new ArrayList<String>();
for (String lista_texto : fileStr) {
lista_lista_CARPETAS.add(lista_texto);
}
Collections.sort(lista_lista_CARPETAS, new AlphanumComparator());
String[] lista_k = f.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
File f = new File(dir, name);
return f.isDirectory();
}
});
FileFilter fileFilter = new FileFilter() {
public boolean accept(File file) {
return file.isDirectory();
}
};
File[] files = f.listFiles(fileFilter);
ArrayAdapter<String> carpetas = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, lista_k);
carpetas.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // The drop down view
sp_titulos_carpetas.setAdapter(carpetas);
//ARRAY CON TITULOS DE ARCHIVOS TXT
String camino = Environment.getExternalStorageDirectory().toString()+"/Textos/" + "Naxos"+ "/";
File t = new File(camino);
String[] lista_textos = t.list();
ArrayList<String> lista_lista_textos = new ArrayList<String>();
for (String lista_texto : lista_textos) {
if (lista_texto.toLowerCase().endsWith(".txt")) {
lista_lista_textos.add(lista_texto);
}
}
for (int index =0; index < lista_lista_textos.size(); index++){
lista_lista_textos.set(index, WordUtils.capitalizeFully(lista_textos[index].toLowerCase().replace(".txt", "")));
}
Collections.sort(lista_lista_textos, new AlphanumComparator());
ArrayAdapter<String> adaptador_textos = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, lista_lista_textos);
adaptador_textos.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // The drop down view
sp_titulos_textos.setAdapter(adaptador_textos);
sp_titulos_textos.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String nombre_texto = parent.getSelectedItem().toString();
File sdcard = new File(Environment.getExternalStorageDirectory().toString()+"/Textos/" + "Naxos/");
//Get the text file
File file = new File(sdcard, nombre_texto);
//Read text from file
StringBuilder text = new StringBuilder();
int BUFFER_SIZE = 8192;
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "Cp1252"),BUFFER_SIZE);
String line;
while ((line = br.readLine()) != null) {
text.append(line);
text.append('\n');
}
}
catch (IOException e) {
//You'll need to add proper error handling here
}
String nuevoTexto = text.toString().replaceAll("\t", " ");
String nuevoTextoA = nuevoTexto.replaceAll("\n", " ");
Holmes1 = nuevoTextoA;
delimitadores = " ";
tokenHolmes1 = new StringTokenizer(Holmes1, " ");
arrayHolmes1 = Holmes1.split(delimitadores);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
和XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="100"
style="@style/spinner_rojo">
<Spinner
android:id="@+id/spinner_titulo_carpetas"
android:layout_width="0dp"
style="@style/spinner_rojo"
android:background="@drawable/spinner_background_holo_light"
android:layout_height="wrap_content"
android:layout_weight="50"></Spinner>
<Spinner
android:id="@+id/spinner_textos_carpetas"
android:layout_width="0dp"
style="@style/spinner_rojo"
android:background="@drawable/spinner_background_holo_light"
android:layout_height="wrap_content"
android:layout_weight="50"></Spinner>
</LinearLayout>
和圖像:
任何人都知道任何可能sulucion顯示下拉列表?
據我所知,你的問題是微調不能表現出它的下拉菜單選擇到選擇其它選項,對不對?我剛剛複製了你的代碼,它對我很好。你這人怎麼回事 ? – Megamind