Я пытаюсь настроить простой текстовый счетчик, который отображает размеры моих продуктов, но моя виртуальная машина остается закрытой. Я сделал подробный анализ точки останова, поэтому, пожалуйста, даже не туда. Что вы думаете о том, почему это не работает?Попытка настроить TextSpinner
11-20 01:07:23.333 11588-11588/com.app.store D/AndroidRuntime﹕ Shutting down VM
Я просто отправлю весь свой фрагмент. Вы заметите, что я пытаюсь передать массив String [] в адаптер. У меня есть тот, который явно определен, и один закомментировал, что я вытаскиваю из другого класса. Ни один из методов не работает.
public class BuyFragment extends Fragment {
private View view;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_buy, container, false);
view = rootView;
return rootView;
}
public int GetProductSizeCode() {
return ((Spinner) view.findViewById(R.id.spinner_sizes)).getSelectedItemPosition();
}
public void DisplayProduct(Product product) throws ParseException {
String productName = product.getName();
String productCost = "USD $" + product.getCost();
String productDescription = product.getDescription();
String careInstructions = product.getCareInstructions();
// String [] productSizes = product.getSizes();
String [] productSizes = new String[] {"1", "2", "3"};
setUpSpinner(productSizes);
((TextView) view.findViewById(R.id.productTitle)).setText(productName);
((TextView) view.findViewById(R.id.productCost)).setText(productCost);
((TextView) view.findViewById(R.id.productDescription)).setText(productDescription);
((TextView) view.findViewById(R.id.careInstructions)).setText(careInstructions);
((ImageView) view.findViewById(R.id.productImage)).setImageResource(product.getTemplateDrawableOverlay());
}
public void setUpSpinner(String[] productSizes) {
Spinner spnr;
spnr = (Spinner)view.findViewById(R.id.spinner_sizes);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
getActivity(),
R.layout.custom_spinner,
R.id.spinner_sizes,
productSizes);
spnr.setAdapter(adapter);
}
}
Это мой обычай вертушка, но вы, вероятно, это не нужно:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
android:background="@color/elgamigrey">
<TextView
android:id="@+id/text_main_seen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Select your size"
android:fontFamily="sans-serif-light"
android:textSize="18sp"
android:textColor="#fff"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
</LinearLayout>
Кто-нибудь есть какие-либо идеи, что происходит? Несмотря на что-то еще, что может произойти, код, по крайней мере, правильный?
Update:
Я имел идентификатор ресурса и расположение в неправильном порядке. при настройке кок Это должно было быть так:
R.layout.custom_spinner,
R.id.spinner_sizes,
Вы не включили все ваши XML-листов .. один, в частности, в custom_spinner.xml. –
см. Документацию конструктора 'ArrayAdapter':' textViewResourceId \t Идентификатор TextView в ресурсе макета, который будет заполнен' – pskink