我在AlertDialog中有两个旋转选择器,旋转选择器看起来很好,项目列表也正确,显示每个列表的第一个项目。但是当我点击任何一个旋转选择器时,下拉菜单不会显示以选择其他项目。旋转选择器无法使用。当我将相同的两个旋转选择器放在AlertDialog外面时,不会发生这种情况。
以下是AlertDialog的代码:
以下是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>
并且有一张图片:
是否有人知道如何解决显示下拉列表的问题?