我有一個expandiblelistview與我自己的適配器,在父母行我有3圖像隱形和3 textviews。設置圖像可見父母在expandablelistview
在活動中我有一個String [] []與數據。 根據我想要將圖像設置爲可見的數據。
林試着這樣做:
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parentView) {
View v;
if (convertView == null) {
v = newGroupView(isExpanded, parentView);
} else {
v = convertView;
}
ponIconos();
return v;
}
private void ponIconos() {
ImageView drCandado = (ImageView) findViewById(R.id.icono_candado);
ImageView drOjos = (ImageView) findViewById(R.id.icono_ojo);
ImageView drUrgente = (ImageView) findViewById(R.id.icono_urgente);
for(int i =0; i<ArrayServicios.size();i++){
if (sIconos[i][0] != "null")
drUrgente.setVisibility(View.VISIBLE);
if (sIconos[i][1] != "null")
drCandado.setVisibility(View.VISIBLE);
if (sIconos[i][2] != "null")
drOjos.setVisibility(View.VISIBLE);
}
}
但它崩潰nullpo .. logcat的:
06-06 08:44:01.066: E/AndroidRuntime(879): FATAL EXCEPTION: main
06-06 08:44:01.066: E/AndroidRuntime(879): java.lang.NullPointerException
06-06 08:44:01.066: E/AndroidRuntime(879): at com.reparalia.movilidad.ListadoServicios$adaptadorLista.ponIconos(ListadoServicios.java:532)
06-06 08:44:01.066: E/AndroidRuntime(879): at com.reparalia.movilidad.ListadoServicios$adaptadorLista.getGroupView(ListadoServicios.java:520)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.widget.ExpandableListConnector.getView(ExpandableListConnector.java:445)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.widget.AbsListView.obtainView(AbsListView.java:2033)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.widget.ListView.makeAndAddView(ListView.java:1772)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.widget.ListView.fillDown(ListView.java:672)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.widget.ListView.fillFromTop(ListView.java:732)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.widget.ListView.layoutChildren(ListView.java:1625)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.widget.AbsListView.onLayout(AbsListView.java:1863)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.view.View.layout(View.java:11278)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.view.ViewGroup.layout(ViewGroup.java:4224)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1617)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.widget.LinearLayout.onLayout(LinearLayout.java:1401)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.view.View.layout(View.java:11278)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.view.ViewGroup.layout(ViewGroup.java:4224)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.widget.ScrollView.onLayout(ScrollView.java:1405)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.view.View.layout(View.java:11278)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.view.ViewGroup.layout(ViewGroup.java:4224)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:925)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.view.View.layout(View.java:11278)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.view.ViewGroup.layout(ViewGroup.java:4224)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.view.View.layout(View.java:11278)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.view.ViewGroup.layout(ViewGroup.java:4224)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.view.View.layout(View.java:11278)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.view.ViewGroup.layout(ViewGroup.java:4224)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.view.View.layout(View.java:11278)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.view.ViewGroup.layout(ViewGroup.java:4224)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1489)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.os.Handler.dispatchMessage(Handler.java:99)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.os.Looper.loop(Looper.java:137)
06-06 08:44:01.066: E/AndroidRuntime(879): at android.app.ActivityThread.main(ActivityThread.java:4424)
06-06 08:44:01.066: E/AndroidRuntime(879): at java.lang.reflect.Method.invokeNative(Native Method)
06-06 08:44:01.066: E/AndroidRuntime(879): at java.lang.reflect.Method.invoke(Method.java:511)
06-06 08:44:01.066: E/AndroidRuntime(879): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-06 08:44:01.066: E/AndroidRuntime(879): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-06 08:44:01.066: E/AndroidRuntime(879): at dalvik.system.NativeStart.main(Native Method)
任何其他方式?
解決方案
/************************************************************************/
/********************* Metodo que GENERA LA VISTA DE LOS PADRES ****************/
@Override
public View getGroupView(final int groupPosition,
final boolean isExpanded, final View convertView,
final ViewGroup parent) {
View v;
if (convertView == null) {
v = newGroupView(isExpanded, parent);
} else **{
v = convertView;
}
llenaPadre(v, padreDesde.get(groupPosition), padreDesde,
padreHasta, groupPosition);
return v;
}
/********************* Metodo que rellena las filas padres ****************/
private void llenaPadre(View v, Map<String, ?> map,
List<? extends Map<String, ?>> datosPadres, int[] padreHasta2,
int groupPosition) {
ImageView drCandado = (ImageView) v
.findViewById(R.id.icono_candado);
ImageView drOjos = (ImageView) v.findViewById(R.id.icono_ojo);
ImageView drUrgente = (ImageView) v
.findViewById(R.id.icono_urgente);
int len = padreHasta2.length - 1;
for (int i = 0; i < len; i++) {
TextView tv = (TextView) v.findViewById(padreHasta2[i]);
if (v != null) {
String texto = (String) map.get(cabecerasPadres[i]);
tv.setText(texto);
if (sIconos[0][groupPosition] != null)
if (drUrgente != null)
drUrgente.setVisibility(View.VISIBLE);
if (sIconos[1][groupPosition] != null)
if (drCandado != null)
drCandado.setVisibility(View.VISIBLE);
if (sIconos[2][groupPosition] != null)
if (drOjos != null)
drOjos.setVisibility(View.VISIBLE);
}
}**
}
你能告訴我們logcat嗎? –
我使用logcat編輯我的問題 – rbrlnx