findViewById()
dönernull
fragmanı sınıfında boş döner.ImageButton
içinToast
findViewById fragmanı sınıfındapublic 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
cevap
0
Aldım .... Ben onGetView içinde findViewById tanımlanmış olan .... Switch
yani mySwitch
getiri null
... yardım lütfen için nesne ancak bir şey gösteriyor OnCreateView tarihinde bildirmek zorunda kaldım.
+1
Arkadaş yorumcular: Bu _is_ bir cevap. Soruna neyin neden olduğunu açıklayan OP. –
+0
** onCreateView ** sadece düzeni döndürdüm. Aslında onun içinde findViewById' olarak adlandırdığınızı bilmiyordum. –
İlgili konular
- 1. Android findViewById hizmet
- 2. findViewById() NullPointerException
- 3. FindViewById Verimliliği
- 4. Nasıl fragmanı
- 5. findViewById vs şişirmek
- 6. parça içinde FindViewById
- 7. DialogFragment içinde FindViewById - NullPointerException
- 8. findviewbyid hatası çözümlenemiyor
- 9. setContentView ve findViewById
- 10. LinearLayout findViewById problemi
- 11. Android BaseAdapter Fragmanı
- 12. Android göstermek/gizlemek fragmanı
- 13. Action Çubuk Fragmanı Etkinliği
- 14. Android Fragmanı onCreateView()
- 15. Araç Çubuğu - findViewbyID dönen null
- 16. Android - findViewById (R.id.list) döndürüyor null
- 17. Neden (ListView) findViewById döndürüyor null?
- 18. Bir etkinliğin dışından findViewById() çağrısı
- 19. android fragmanı android.support.v4.app.Fragment; Hata
- 20. $ argv sınıfında
- 21. Java sınıfında
- 22. Android Fragmanı ve Bağımlılık Enjeksiyon
- 23. Android: Fragmanı AsyncTask (Aktivite Yok)
- 24. Fragmanlar ve Fragmanı olan TabHost
- 25. Yükleme Fragmanı değilse Null - Android
- 26. En İyileştirme C# Kod Fragmanı
- 27. Apache ile yeniden yönlendirme Fragmanı
- 28. android fragmanı, düğme metni ayarlayamıyor
- 29. GoogleMap Fragmanı Blokları Özel Dokunma Etkinlikleri
- 30. Google Map v2 Fragmanı için OnDragListener Oluşturma
Lütfen burada xml göster –
Ve lütfen hata. Ve bu sizin 'parça sınıfınız' değil, 'adaptör' sınıfınız –
LayoutInflater inflater = LayoutInflater.from (getContext()); 'LayoutInflater inflater = ((LayoutInflater) context.getSystemService (Context.LAYOUT_INFLATER_SERVICE)) ; – ELITE