findViewById()
возвращаетnull
в классе фрагментов.Toast
дляImageButton
показывает что-то, кроме объекта дляSwitch
т.е.mySwitch
возвращаетсяnull
... пожалуйста, помогите ....findViewById возвращает null в классе фрагментовpublic MyAdapter(Context context, List<ListItems> values) { super(context, R.layout.list_item, values); } @Override public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; LayoutInflater inflater = LayoutInflater.from(getContext()); if(v == null){ v = inflater.inflate(R.layout.list_item, parent, false); } ListItems currLoc = LocationList.get(position); TextView theTextView = (TextView) v.findViewById(R.id.list_item_textview); theTextView.setText(currLoc.getLocation()); TextView theTextView2 = (TextView) v.findViewById(R.id.list_item_textviewP); theTextView2.setText(currLoc.getProfile()); ImageView theImageView = (ImageView) v.findViewById(R.id.imageview1); Toast.makeText(getActivity(), "image view="+theImageView, Toast.LENGTH_SHORT).show(); theImageView.setImageResource(R.drawable.bullet); Switch mySwitch=(Switch) v.findViewById(R.id.onoff); Toast.makeText(getActivity(), ""+mySwitch, Toast.LENGTH_SHORT).show(); return v; }
2
A
ответ
0
Я получил его .... я определил findViewById в onGetView Мне пришлось объявить его на OnCreateView Извините .....
+1
Рецензенты: этот _is_ ответ. Это ОП объясняет, что вызвало проблему. –
+0
Я думал, что ** onCreateView ** просто возвращает макет. Я не знал, что вы на самом деле называете 'findViewById' внутри него. –
Смежные вопросы
- 1. findViewById() возвращает null в классе TabActivity
- 2. findViewById (android.R.id.progress) возвращает null
- 3. findViewById возвращает null в Listfragment
- 4. Android findViewById возвращает null
- 5. Почему findViewById возвращает null?
- 6. Android: findViewById возвращает null?
- 7. Switch findViewById возвращает null
- 8. FindViewById возвращает null?
- 9. findViewById возвращает null TextView
- 10. Android - findViewById возвращает null
- 11. Android findViewById() возвращает null
- 12. findViewById (R.id.screen) возвращает null
- 13. findViewById() возвращает Null, Why?
- 14. Android, findViewById возвращает null
- 15. findViewById() возвращает null
- 16. AdMob findViewById возвращает null
- 17. Android: findViewById возвращает null
- 18. findViewById возвращает null
- 19. Android: Findviewbyid() возвращает null
- 20. ImageButton findViewById возвращает null
- 21. ListView - findviewbyid возвращает null
- 22. findViewById возвращает null - почему?
- 23. getActivity(). FindViewById (R.layout.contacts_list_view) возвращает null
- 24. findviewbyid возвращает null в Android
- 25. findViewById в MainActivity возвращает null
- 26. findViewById возвращает null для action_bar_title
- 27. findViewById для MenuItem возвращает null
- 28. findViewById возвращает null (еще раз)
- 29. findViewById() возвращает null во фрагменте
- 30. findViewById возвращает null - Android - setContentView
Пожалуйста, покажите xml здесь –
И ошибка, пожалуйста. И это не ваш «класс фрагментов», это ваш класс «адаптер», который –
заменит «LayoutInflater inflater = LayoutInflater.from (getContext());' by 'LayoutInflater inflater = ((LayoutInflater) context.getSystemService (Context.LAYOUT_INFLATER_SERVICE)) ; ' – ELITE