Cześć, klepię sobie od jakiegoś czasu projekt i stanąłem w martwym punkcie bo aplikacja przy crashu nie rzuca żadnym wyjątkiem jedynie dostaję komunikat
I/Process: Sending signal. PID: 24308 SIG: 9
To co usiłuję zrobić:
Muszę wypełnić ListView danymi, które dostaję na starcie aktywności. Dane które dostaję to lista obiektów zawierających dwa Stringi.
Jedna pozycja ListView ma odpowiadać jednemu obiektowi!
Layout dla jednej pozycji ListView wygląda w uproszczeniu tak:
<LinearLayout />| img |
<LinearLayout />| view |
Dwa wiersze na koncu których jest obrazek.
jako że nie wiem ile słów będzie w polach obiektów, które dostaję, muszę do obu tych linear layoutów dodawać dynamicznie widoki
widok który dodaję to layout składający się z dwóch textView, nagłówek i wartość.
Zrobiłem sobie taką klasę która zwraca mi widok tych dwóch TextView:
public static class DefineProductView {
private View defineProductView;
private LayoutInflater inflater;
private String labelText;
private String valueText;
private TextView label;
private TextView value;
DefineProductView(Context context, String noAssignment, String word) {
init(context);
labelText = noAssignment;
valueText = word;
}
void init(Context context) {
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
View getView() {
if(defineProductView == null) {
defineProductView = inflater.inflate(R.layout.bill_define_product_item, null);
label = (TextView) defineProductView.findViewById(R.id.label);
value = (TextView) defineProductView.findViewById(R.id.value);
label.setText(labelText);
value.setText(valueText);
defineProductView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
}
return defineProductView;
}
}
xml tego widoku:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginEnd="2dp">
<TextView
android:id="@+id/label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#444444"
android:textSize="8sp"
android:textAlignment="center"
android:textAllCaps="true"
android:background="@color/transparentLightGrey"/>
<TextView
android:id="@+id/value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:textColor="@color/fontColorDark"
android:textSize="14sp"
android:background="@color/transparentWhite"/>
</LinearLayout>
Ogarnąłem sobie do tego Arraydaptera:
@Override
public View getView(int position, View rowView, ViewGroup parent) {
if(rowView == null) {
rowView = LayoutInflater.from(getContext()).inflate(R.layout.bill_product_row, parent, false);
}
ProductViewHandle handle = new ProductViewHandle(
rowView.findViewById(R.id.productNumber),
rowView.findViewById(R.id.productNameStrings),
rowView.findViewById(R.id.productPriceStrings),
rowView.findViewById(R.id.acceptProduct),
rowView.findViewById(R.id.deleteProduct)
);
TwoLineBillAdapterObject object = getItem(position);
handle.id.setText("Produkt " + (position + 1));
handle.accept.setImageResource(R.drawable.ic_accept_green);
handle.delete.setImageResource(R.drawable.ic_delete_product);
initNames(handle, object.getNameViews());
//initPrices(handle, object.getPriceViews());
return rowView;
}
private void initPrices(ProductViewHandle handle, ArrayList<View> priceViews) {
//handle.price.removeAllViews();
for (View productView : priceViews) {
handle.price.addView(productView, new LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
}
}
private void initNames(ProductViewHandle handle, ArrayList<View> nameViews) {
//handle.name.removeAllViews();
for (View productView : nameViews) {
handle.name.addView(productView);
}
}
Apkę wyrzuca w momencie wywołania handle.name.addView