android - if statement colors in listview -


इस कथन के साथ, सूची दृश्य में डाला,

  सार्वजनिक दृश्य getView (int pos, बच्चे, ViewGroup पैरेंट देखें) {SharedPreferences prefs = mContext.getSharedPreferences (MY_PREFERENCES, Context.MODE_PRIVATE); स्ट्रिंग ऐनो = प्रीफ़ेक्स .get स्ट्रिंग (एननो, "2014"); स्ट्रिंग मलटाटिया = प्रीफ़्स .get स्ट्रिंग (म्यूटा, "एम"); स्ट्रिंग ferie_1 = prefs.getString (FERIE, "एफ"); स्ट्रिंग par_1 = prefs.getString (PAR, "PAR"); धारक mHolder; लेआउटइनफ्लाटर लेआउटआइफ़्लेटर; // पाठ जिसमें आप "एम" को ढूंढना चाहते हैं यदि (child == null) {layoutInflater = (LayoutInflater) mContext.getSystemService (context.LAYOUT_INFLATER_SERVICE); बच्चा = लेआउटइफलेटर.inफलेट (आर.लेआउट.रो, नल); mHolder = नया होल्डर (); MHolder.txt_notes = (TextView) child.findViewById (R.id.txt_notes); MHolder.txt_mese = (पाठदृश्य) child.findViewById (R.id.txt_mese); MHolder.txt_giorni = (टेक्स्टदृश्य) child.findViewById (R.id.txt_giorni); MHolder.txt_turno = (TextView) child.findViewById (R.id.txt_turno); MHolder.txt_ore = (पाठदृश्य) child.findViewById (R.id.txt_ore); MHolder.txt_id = (TextView) child.findViewById (R.id.txt_id); child.setTag (mHolder); } और {mHolder = (धारक) child.getTag (); } MHolder.txt_giorni.setText (giorniName.get (pos)); mHolder.txt_turno.setText (turnoName.get (पीओएस)); mHolder.txt_ore.setText (oreName.get (पीओएस)); mHolder.txt_id.setText (dataName.get (पीओएस)); mHolder.txt_giorni.setText (giorniName.get (पीओएस)); mHolder.txt_turno.setText (turnoName.get (पीओएस)); mHolder.txt_ore.setText (oreName.get (पीओएस)); mHolder.txt_id.setText (dataName.get (पीओएस)); स्ट्रिंग टूनी = टर्नओनाम.गेट (पॉज़); स्ट्रिंग मेसे = मेसेनाम.गेट (पॉज़); स्ट्रिंग डेटा = डेटानाम.गेट (पॉज़); स्ट्रिंग Giorni = giorniName.get (pos); स्ट्रिंग नोट्स = नोट्सनाम.गेट (पॉज़); अगर (टर्नियल! = नल) यदि (टर्नएएएजल्स ("" + मलटाइया)) {mHolder.txt_turno.setTextColor (Color.RED); mHolder.txt_ore.setTextColor (Color.RED); } और अगर (टर्नएएएजल्स ("+ + par_1") {mHolder.txt_turno.setTextColor (Color.GREEN); mHolder.txt_ore.setTextColor (Color.GREEN); } और अगर (टर्नइएएजल्स ("+ फेरी_1")) {mHolder.txt_turno.setTextColor (Color.YELLOW); mHolder.txt_ore.setTextColor (Color.YELLOW); } और mHolder.txt_turno.setTextColor (Color.WHITE); यदि (नोट्स! = नल) {if (! Notes.equalsIgnoreCase ("")) {mHolder.txt_notes.setBackgroundColor (Color.GREEN); mHolder.txt_notes.setTextColor (Color.BLUE); mHolder.txt_notes.setText ( "नोटा"); } अन्य {mHolder.txt_notes.setBackgroundColor (Color.RED); }} अगर (जीओर्नी! = नल) अगर (जीओर्नी.एजलल्स ("सब")) {mHolder.txt_giorni.setBackgroundColor (रंग। पीरसेकॉलर ("# एफएफए 500")); } else if (Giorni.equals ("Dom") {mHolder.txt_giorni.setBackgroundColor (Color.RED);} और mHolder.txt_giorni.setBackgroundColor (Color.BLACK); अगर (Giorni! = null) अगर (Giorni.equals ( "सब")) {mHolder.txt_id.setBackgroundColor (Color.parseColor ("# FFA500")); else if (Giorni.equals ("डोम") {mHolder.txt_id.setBackgroundColor (Color.RED);} अन्य mHolder .txt_id.SetBackgroundColor (Color.BLACK); वापसी बच्चे;} सार्वजनिक वर्ग धारक {टेक्स्टव्यू txt_notes; टेक्स्टव्यू txt_mese; टेक्स्टव्यू txt_giorni; टेक्स्टव्यू txt_turno; textView txt_ore; textView txt_id;}}   

I अगर डेटा रिक्त है, तो यह लाल होना चाहिए। मेरी समस्या यह है कि अगर मैं listview का स्क्रॉल करना कोड>, हर एक TextView हरे रंग की बारी, अगर मैं सही जगह पर वापस पूरे वर्ग का ताज़ा करता हूँ। मैं इस समस्या को कैसे ठीक कर सकता हूं? < P>

धारक < / कोड> और setTag , getTag ठीक लगता है! इसलिए एकमात्र कारण है कि दोषपूर्ण रीसायकल का कारण आपके डेटा पर null मान हो सकता है।

इसलिए यदि इनमें से कोई एक हो जाता है तो null <पूर्व> स्ट्रिंग टर्निया = टर्नोनाम.गेट (पॉज़); स्ट्रिंग मेसे = मेसेनाम.गेट (पॉज़); स्ट्रिंग डेटा = डेटानाम.गेट (पॉज़); स्ट्रिंग Giorni = giorniName.get (pos); स्ट्रिंग नोट्स = नोट्सनाम.गेट (पॉज़);

फिर setTextColor या setBackgroundColor को TextView के लिए नहीं बुलाया जा रहा है, परिणामस्वरूप यह रहता है पिछले कोड को धारक से पुनर्नवीनीकरण (xml पर एक सेट नहीं)। इससे बचने के लिए आपको सभी मामलों में "हार्डकोड" रंग चाहिए।

  यदि (नोट्स! = नल) {if (! Notes.equalsIgnoreCase ("")) {mHolder.txt_notes.setBackgroundColor ( हरा रंग करें); mHolder.txt_notes.setTextColor (Color.BLUE); mHolder.txt_notes.setText ( "नोटा"); } अन्य {mHolder.txt_notes.setBackgroundColor (Color.RED); }} और {mHolder.txt_notes.setBackgroundColor (your_default_color_here); }   

यदि null और खाली को उसी तरह से नियंत्रित किया जाता है जिस तरह से आप TextUtils.isEmpty (Notes) का उपयोग कर सकते हैं जो दोनों मामलों में सही होता है।

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -