0
我在這裏跟隨了很多關於如何設置微調內容的問題,但沒有人爲我工作,我仍然收到錯誤。設置微調內容
這是佈局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" android:id="@+id/librosDisponibles">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/libDispText"
android:textAppearance="?android:attr/textAppearanceMedium" >
</TextView>
<Spinner
android:id="@+id/librosDispSpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</Spinner>
<TableRow android:id="@+id/tableRow1" android:layout_width="match_parent" android:layout_height="wrap_content">
<Button
android:id="@+id/seleccionarBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Seleccionar" >
</Button>
<Button
android:id="@+id/cancelarBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancelar" >
</Button>
</TableRow>
<TextView
android:id="@+id/elementosTxtVw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:text="TextView"
android:visibility="invisible"
android:focusable="false"/>
</LinearLayout>
沒什麼特別的存在,只是一個TextView作爲微調的標籤,微調本身和一對按鈕,要麼選擇微調選項或取消選擇和在ArrayAdapter構造函數上請求textview。不知道爲什麼,每次教程中,我看到,一個ArrayAdapter構造問德情況下,微調ID和內容,但對那些我得到,問語境,TextViewID和內容
package com.aguahillo.sislec;
import org.ksoap2.serialization.SoapObject;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.view.View;
import android.view.View.OnClickListener;
public class FormaLibrosDisponibles
{
SisLec sisLec;
private Spinner librosDisponibles;
private ArrayAdapter<String> elementosArrayAdapter;
private Button selecBtn;
private Button cancelarBtn;
private OnClickListener selecClk;
private OnClickListener cancelarClk;
private LinearLayout disenio;
public FormaLibrosDisponibles(SisLec _sisLec)
{
sisLec = _sisLec;
disenio = (LinearLayout) View.inflate(sisLec, R.layout.librosdisponibles, null);
selecClk = new OnClickListener()
{
public void onClick(View v)
{
seleccionarBtnClick(v);
}
};
cancelarClk = new OnClickListener()
{
public void onClick(View v)
{
cancelarBtnClick(v);
}
};
selecBtn = (Button) disenio.findViewById(R.id.seleccionarBtn);
selecBtn.setOnClickListener(selecClk);
cancelarBtn = (Button) disenio.findViewById(R.id.cancelarBtn);
cancelarBtn.setOnClickListener(cancelarClk);
}
public void mostrar()
{
sisLec.setContentView(R.layout.librosdisponibles);
}
public void enlistarLibros() throws Exception
{
sisLec.cuerpoRespuesta = sisLec.serviciosWeb.obtenerRutas(sisLec.usuario, sisLec.contrasena);
if(sisLec.cuerpoRespuesta.getPropertyCount() > 0)
{
sisLec.tabla = (SoapObject) sisLec.cuerpoRespuesta.getProperty(0);
ArrayAdapter<String> elementosArrayAdapter = new ArrayAdapter<String>(sisLec, android.R.layout.simple_spinner_item);
elementosArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
librosDisponibles = (Spinner) disenio.findViewById(R.id.librosDispSpinner);
librosDisponibles.setAdapter(elementosArrayAdapter);
for(int i = 0; i < sisLec.tabla.getPropertyCount(); i++)
{
sisLec.lineaTabla = (SoapObject) sisLec.tabla.getProperty(i);
if(sisLec.lineaTabla.getProperty("RUTA").toString().equals("0"))
{
sisLec.mensaje("No hay libros asginados");
return;
}
elementosArrayAdapter.add(obtenerElemento(sisLec.lineaTabla.getProperty("RUTA").toString(), sisLec.lineaTabla.getProperty("ITINERARIO").toString(), sisLec.lineaTabla.getProperty("ESTADO").toString()));
}
librosDisponibles.setSelection(0);
}
else
{
sisLec.frmLogin.mostrar();
sisLec.mensaje("No hay libros disponibles por el momento");
}
}
/**
* Función sencilla para crear las entradas de la lista de libros disponibles
* y sus estados
*/
private String obtenerElemento(String ruta, String itinerario, String estado)
{
if (estado.equals("ERI03"))
return "Ruta " + ruta + " Itin " + itinerario + " Env";
else if (estado.equals("ERI04"))
return "Ruta " + ruta + " Itin " + itinerario + " Proc";
else if (estado.equals("ERI06"))
return "Ruta " + ruta + " Itin " + itinerario + " Sobr";
else if (estado.equals("ERI07"))
return "Ruta " + ruta + " Itin " + itinerario + " Sobr Proc";
return "";
}
public void seleccionarBtnClick(View v)
{
sisLec.mensaje("Se selecciono: " + Integer.toString(librosDisponibles.getSelectedItemPosition()) + " " + librosDisponibles.getSelectedItem().toString());
}
public void cancelarBtnClick(View v)
{
sisLec.frmLogin.mostrar();
}
}
代碼僅提取物來自webService的信息將其存儲在一個String數組中,然後將其傳遞給ArrayAdapter以將其設置爲Spinner。
這是我得到的錯誤(來自logcat的
> 11-16 18:45:58.859: E/AndroidRuntime(700): FATAL EXCEPTION: main 11-16
> 18:45:58.859: E/AndroidRuntime(700):
> android.content.res.Resources$NotFoundException: Resource ID
> #0x7f050007 type #0x12 is not valid 11-16 18:45:58.859: E/AndroidRuntime(700): at
> android.content.res.Resources.loadXmlResourceParser(Resources.java:1874)
> 11-16 18:45:58.859: E/AndroidRuntime(700): at
> android.content.res.Resources.getLayout(Resources.java:731) 11-16
> 18:45:58.859: E/AndroidRuntime(700): at
> android.view.LayoutInflater.inflate(LayoutInflater.java:318) 11-16
> 18:45:58.859: E/AndroidRuntime(700): at
> android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:332)
> 11-16 18:45:58.859: E/AndroidRuntime(700): at
> android.widget.ArrayAdapter.getView(ArrayAdapter.java:323) 11-16
> 18:45:58.859: E/AndroidRuntime(700): at
> android.widget.AbsSpinner.onMeasure(AbsSpinner.java:192) 11-16
> 18:45:58.859: E/AndroidRuntime(700): at
> android.view.View.measure(View.java:8171) 11-16 18:45:58.859:
> E/AndroidRuntime(700): at
> android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
> 11-16 18:45:58.859: E/AndroidRuntime(700): at
> android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
> 11-16 18:45:58.859: E/AndroidRuntime(700): at
> android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
> 11-16 18:45:58.859: E/AndroidRuntime(700): at
> android.widget.LinearLayout.onMeasure(LinearLayout.java:304) 11-16
> 18:45:58.859: E/AndroidRuntime(700): at
> android.view.View.measure(View.java:8171) 11-16 18:45:58.859:
> E/AndroidRuntime(700): at
> android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
> 11-16 18:45:58.859: E/AndroidRuntime(700): at
> android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 11-16
> 18:45:58.859: E/AndroidRuntime(700): at
> android.view.View.measure(View.java:8171) 11-16 18:45:58.859:
> E/AndroidRuntime(700): at
> android.widget.LinearLayout.measureVertical(LinearLayout.java:526)
> 11-16 18:45:58.859: E/AndroidRuntime(700): at
> android.widget.LinearLayout.onMeasure(LinearLayout.java:304) 11-16
> 18:45:58.859: E/AndroidRuntime(700): at
> android.view.View.measure(View.java:8171) 11-16 18:45:58.859:
> E/AndroidRuntime(700): at
> android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
> 11-16 18:45:58.859: E/AndroidRuntime(700): at
> android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 11-16
> 18:45:58.859: E/AndroidRuntime(700): at
> android.view.View.measure(View.java:8171) 11-16 18:45:58.859:
> E/AndroidRuntime(700): at
> android.view.ViewRoot.performTraversals(ViewRoot.java:801) 11-16
> 18:45:58.859: E/AndroidRuntime(700): at
> android.view.ViewRoot.handleMessage(ViewRoot.java:1727) 11-16
> 18:45:58.859: E/AndroidRuntime(700): at
> android.os.Handler.dispatchMessage(Handler.java:99) 11-16
> 18:45:58.859: E/AndroidRuntime(700): at
> android.os.Looper.loop(Looper.java:123) 11-16 18:45:58.859:
> E/AndroidRuntime(700): at
> android.app.ActivityThread.main(ActivityThread.java:4627) 11-16
> 18:45:58.859: E/AndroidRuntime(700): at
> java.lang.reflect.Method.invokeNative(Native Method) 11-16
> 18:45:58.859: E/AndroidRuntime(700): at
> java.lang.reflect.Method.invoke(Method.java:521) 11-16 18:45:58.859:
> E/AndroidRuntime(700): at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
> 11-16 18:45:58.859: E/AndroidRuntime(700): at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 11-16
> 18:45:58.859: E/AndroidRuntime(700): at
> dalvik.system.NativeStart.main(Native Method)
希望你能幫助我直接辯論,因爲一切,我在網上找的,沒有幫助我很多
編輯1:好吧,我設法至少現在顯示的佈局,但現在它向我展示了微調空,以及bouth按鈕無能爲力