Android Question Loading JSON file from a website & Parsing JSON data of Multiple Arrays

Shahid Saeed

Active Member
Licensed User
Longtime User
I went through all the Tutorials about usage of JSON file, and currently found only few methods, Local JSON file and remote JSON file.

My Question is the method for remote JSON files which provides a way through connecting to MySQL server and fetch the data and parse into JSON. But what if someone doesn't have access over to MySQL and the only source he have is the JSON file link e.g (http://www.somewebsite.com/JSON/JSON.php). What will be the method to include that JSON file, or if there is a way to read data from remote file and store into Assets folder as local JSON file.

My Second Question is about Parsing specific JSON Data from Multiple Arrays

for example :

B4X:
{
   "news_sections": [
      {
         "section_title": "الأخبار",
         "news": [
            {
               "news_date": "الأربعاء ، ١٩ مارس  ٢٠١٤",
               "news_title": "الوارية تنتزع سيف صاحب السمو رئيس الدولة",
               "news_summary": "أهدى معالي الشيخ سلطان بن حمدان آل نهيان مستشار صاحب السمو رئيس الدولة، رئيس اتحاد سباقات الهجن، إنجاز «هجن الرئاسة» وفوزها بسيفي الحول والزمول، وخنجر الزمول المحليات، إلى صاحب السمو الشيخ خليفة بن زايد آل نهيان رئيس الدولة حفظه الله،",
               "news": "<p align=\"right\">أهدى معالي الشيخ سلطان بن حمدان آل نهيان مستشار صاحب السمو رئيس الدولة، رئيس اتحاد سباقات الهجن، إنجاز «هجن الرئاسة» وفوزها بسيفي الحول والزمول، وخنجر الزمول المحليات، إلى صاحب السمو الشيخ خليفة بن زايد آل نهيان رئيس الدولة حفظه الله، مؤكداً أن فوز هجن الرئاسة بـ «ناموس القائد»، يمثل أعلى وأروع تكريم لمسيرة إنجازاتها المتلاحقة، التي توجتها أمس بتتويج مستحق واستثنائي، مشيراً إلى أن ما شهده المهرجان الختامي بالوثبة، يمثل شاهداً حياً على دعم وعطاء القيادة للرياضات التراثية، وفي مقدمتها سباقات الهجن التي تعيش عصرها الذهبي. <\/p><p align=\"right\">كما أهدى معاليه إنجاز «هجن الرئاسة» إلى الفريق أول سمو الشيخ محمد بن زايد آل نهيان ولي عهد أبوظبي نائب القائد الأعلى للقوات المسلحة، مشيداً بدعم سموه المتواصل للرياضة والرياضيين، وللرياضات التراثية بصفة خاصة، وفي مقدمتها سباقات الهجن، التي يحفظ منتسبوها لسموه أياديه البيضاء على هذه الرياضة، والتي تمثلت في عدة سباقات تطوف إمارات الدولة باسم سموه، إضافة إلى الدعم الدائم والسخي للسباقات في كل الميادين، ما جعل الإمارات وجهة للملاك والمضمرين من دول الخليج كافة. <\/p><p align=\"right\">وثمن معالي الشيخ سلطان بن حمدان آل نهيان مستشار صاحب السمو رئيس الدولة، رئيس اتحاد سباقات الهجن، دعم وعطاء سمو الشيخ منصور بن زايد آل نهيان، نائب رئيس مجلس الوزراء وزير شؤون الرئاسة، مؤكداً أن عطاء سموه بلا حدود، وأن ما شهدته سباقات الهجن ومختلف الرياضات التراثية من تطور، كان نتاجاً لأفكار سموه الوثابة التي لا تحدها حدود، وتنطلق من حب عميق للوطن، ومن ربط رائع بين الماضي بموروثه العريق والحاضر بمعطيات التطور، تطلعاً إلى مستقبل حافل بإذن الله لدولتنا الناهضة. <br><\/p>",
               "image": "http://www.prcamels.ae/images/news/npic18711720.jpg"
            },
            {
               "news_date": "الأحد ، ١٦ مارس  ٢٠١٤",
               "news_title": "الخفيفة لـ «هجن الرئاسة» تتصدر منافسات الشيوخ للثنايا",
               "news_summary": "شهد معالي الشيخ سلطان بن حمدان بن محمد آل نهيان مستشار صاحب السمو رئيس الدولة حفظه الله، رئيس اتحاد سباقات الهجن، منافسات اليوم السادس للمهرجان الختامي السنوي لسباقات الهجن بمنطقة الوثبة بالعاصمة أبوظبي",
               "news": "<div style=\"text-align: right;\">شهد معالي الشيخ سلطان بن حمدان بن محمد آل نهيان مستشار صاحب السمو رئيس الدولة حفظه الله، رئيس اتحاد سباقات الهجن، منافسات اليوم السادس للمهرجان الختامي السنوي لسباقات الهجن بمنطقة الوثبة بالعاصمة أبوظبي، والتي خصصت لسن (الثنايا) الطفح ولمسافة 6 كلم، كما شهد المنافسات، جمهور غفير من محبي رياضة سباقات الهجن من أبناء الدولة وإخوانهم من دول مجلس التعاون الخليجي.<\/div><div style=\"text-align: right;\"><br><\/div><div style=\"text-align: right;\">وتصدرت (الخفيفة) لهجن الرئاسة مع المضمر مبارك أحمد مطر الخييلي الشوط الأول والمخصص للبكار المحليات وأحرزت المركز الأول والناموس بعد أن قطعت مسافة الشوط في توقيت (9:15:2 دقيقة)، وجاءت في المركز الثاني (احتلال) لهجن الرئاسة والمضمر عيسى أحمد مطر الخييلي بتوقيت وقدره(9:17:2)، وحلت ثالثة (الوجبة) لهجن الشحانية والمضمر سالم فاران المري بتوقيت (9:20:00).<\/div><div style=\"text-align: right;\"><br><\/div>",
               "image": "http://www.prcamels.ae/images/news/npic27449365.jpg"
            },
            {
               "news_date": "السبت ، ١٥ مارس  ٢٠١٤",
               "news_title": "هجن الرئاسة.. «خط أحمر»",
               "news_summary": "شهد سمو الشيخ حمدان بن محمد بن راشد آل مكتوم ولي عهد دبي، منافسات اليوم الخامس للمهرجان الختامي السنوي لسباقات الهجن في منطقة الوثبة بالعاصمة أبوظبي",
               "news": "<div style=\"text-align: right;\">شهد سمو الشيخ حمدان بن محمد بن راشد آل مكتوم ولي عهد دبي، منافسات اليوم الخامس للمهرجان الختامي السنوي لسباقات الهجن في منطقة الوثبة بالعاصمة أبوظبي، كما شهد المنافسات معالي الشيخ سلطان بن حمدان بن محمد آل نهيان مستشار صاحب السمو رئيس الدولة حفظه الله، رئيس اتحاد سباقات الهجن، والشيخ راشد بن حمدان بن محمد آل نهيان، والشيخ خليفة بن سيف بن محمد آل نهيان، والشيخ المر بن مكتوم آل مكتوم، وجمع غفير من محبي رياضة سباقات الهجن من أبناء الدولة وإخوانهم أبناء دول مجلس التعاون الخليجي.<\/div><div style=\"text-align: right;\"><br><\/div><div style=\"text-align: right;\">وكانت هجن الرئاسة قد حلقت كعادتها بناموس الإبداع وأثبتت أنها «خط أحمر» على صعيد المنافسة، بعد أن اكتسحت معظم المراكز، وغردت وحدها خارج السرب، في مكانتها التي لا تدانيها فيها غيرها، وليس أدل على ذلك من حصولها على «هاتريك» في الأشواط الرئيسية لمنافسات «الإيذاع»، التي أقيمت لمسافة 6 كلم في الميدان الجنوبي للفترة المسائية، والتي شهدت تصدر (كيف) لهجن الرئاسة والمضمر راشد محمد بالسم المنصوري منافسات الشوط الأول «أبكار مفتوح» وفازت بالمركز الأول بعد أن تصدرت المراحل الأخيرة وحققت أفضل توقيت لفئة الإيذاع بعد أن قطعت المسافة بتوقيت وقدره (8:48:5)، وجاءت في المركز الثاني (كوره) لهجن الرئاسة والمضمر راشد محمد بالسم المنصوري وقطعت المسافة بتوقيت وقدره (8:49:8)، وفي المركز الثالث (هدوء) لهجن العاصفة والمضمر حمد راشد غدير الكتبي بتوقيت وقدره (8:56:1).<\/div><div style=\"text-align: right;\"><br><\/div>",
               "image": "http://www.prcamels.ae/images/news/npic77497797.jpg"
            }
         ]
      },
      {
         "section_title": "الأخبار العامة",
         "news": [
            {
               "news_date": "الخميس ، ٣٠ يناير  ٢٠١٤",
               "news_title": "سلطان بن حمدان: دعم القيادة الرشيدة وراء تفوق هجن الإمارات",
               "news_summary": "هنأ معالي الشيخ سلطان بن حمدان بن محمد آل نهيان مستشار صاحب السمو رئيس الدولة رئيس اتحاد سباقات الهجن، صاحب السمو الشيخ خليفة بن زايد آل نهيان رئيس الدولة حفظه الله، بنجاح العملية الجراحية داعيا الله عز وجل أن يمن على سموه بالصحة والعافية، كما هنأ معاليه صاحب السمو رئيس الدولة بإنجاز هجن الرئاسة بفوز «سمحة» بالسيف الذهبي للحول و«معزز» بالخنجر الذهبي للزمول المحليات.",
               "news": "<div style=\"text-align: right;\">هنأ معالي الشيخ سلطان بن حمدان بن محمد آل نهيان مستشار صاحب السمو رئيس الدولة رئيس اتحاد سباقات الهجن، صاحب السمو الشيخ خليفة بن زايد آل نهيان رئيس الدولة - حفظه الله - بنجاح العملية الجراحية داعيا الله عز وجل أن يمن على سموه بالصحة والعافية، كما هنأ معاليه صاحب السمو رئيس الدولة بإنجاز هجن الرئاسة بفوز «سمحة» بالسيف الذهبي للحول و«معزز» بالخنجر الذهبي للزمول المحليات في مهرجان أمير قطر للهجن العربية الأصيلة، وهنأ معاليه الفريق أول سمو الشيخ محمد بن زايد آل نهيان ولي عهد أبوظبي نائب القائد الأعلى للقوات المسلحة بالإنجاز المميز، كما هنأ معاليه سمو الشيخ منصور بن زايد آل نهيان نائب رئيس مجلس الوزراء وزير شؤون الرئاسة بتفوق هجن الرئاسة في ميدان الشحانية، وتوجه معاليه بالتهنئة إلى شعب الإمارات بهذا الإنجاز الكبير.<\/div><div style=\"text-align: right;\"><br><\/div><div style=\"text-align: right;\">&nbsp;وقال معاليه: «هذه الإنجازات هي نتاج للدعم غير المحدود الذي تجده رياضات الآباء والأجداد عامة وسباقات الهجن على وجه الخصوص، من سموه التي تهدف إلى تعزيز قيم الماضي في نفوس الأبناء والأجيال المقبلة، مشيراً معاليه إلى أن هذا الدعم السخي كفل لهجن الرئاسة تحقيق الانتصارات والتتويج بأرفع الألقاب في السباقات التي تشارك فيها داخل وخارج الدولة. وأكد معاليه أن الفريق أول سمو الشيخ محمد بن زايد آل نهيان ولي عهد أبوظبي نائب القائد الأعلى للقوات المسلحة يقدم الدعم والاهتمام الكبيرين لسباقات الهجن مما وضعها على طريق التوهج المستمر وفتح الطريق لحصد الإنجازات والتوشح بالألقاب وانعكس ذلك على هجن الرئاسة والتي تخوض التحديات بحثاً عن القمة في كافة المحافل الداخلية والخارجية.<\/div><div style=\"text-align: right;\"><br><\/div><div style=\"text-align: right;\">وأوضح معاليه أن دعم ومتابعة سمو الشيخ منصور بن زايد آل نهيان نائب رئيس مجلس الوزراء وزير شؤون الرئاسة لسباقات الهجن وتوفير كافة المتطلبات ظل يصب في اتجاه تطويرها والوصول بها إلى أعلى المراتب، وما إنجاز هجن الرئاسة في مهرجان أمير قطر إلا محصلة ونتاج طبيعي للدعم الكبير الذي يقدمه سموه لرياضة سباقات الهجن.<\/div><div style=\"text-align: right;\"><br><\/div><div style=\"text-align: right;\">وأوضح معاليه «سباقات الهجن في الإمارات محظوظة بالاهتمام الكبير والدعم الذي تجده من القيادة الرشيدة التي تحرص على غرس هذا الإرث التاريخي في نفوس الشباب لتواصل رياضة الآباء والأجداد مسيرتها مع الأجيال والتي تحمل العديد من المعاني العميقة في نفوس الجميع».<\/div><div style=\"text-align: right;\">وأشار معاليه إلى أن هجن الرئاسة تخوض كل التحديات للتتويج بالناموس في السباقات التي تقام محلياً أو في المنافسات الخارجية لذا تأتي مشاركاتها مليئة بالتحدي بحثاً عن التتويج، وهنا نجد أن تتويجها بسيف أمير قطر في الشحانية وبستة رموز أخرى هو امتداد لإنجازات متتالية ظلت تحققها على الدوام، ونأمل أن تتواصل مسيرة نجاحاتها في كل السباقات المقبلة.<\/div><div style=\"text-align: right;\"><br><\/div>",
               "image": "http://www.prcamels.ae/images/news/npic89046723.jpg"
            },
            {
               "news_date": "الأحد ، ٠٨ ديسمبر  ٢٠١٣",
               "news_title": "سمو الشيخ منصور بن زايد آل نهيان يحضر مأدبة غداء أقامها معالي الشيخ سلطان بن حمدان آل نهيان",
               "news_summary": "حضر سمو الشيخ منصور بن زايد آل نهيان نائب رئيس مجلس الوزراء وزير شؤون الرئاسة، مأدبة غداء أقامها لسموه معالي الشيخ سلطان بن حمدان بن محمد آل نهيان، مستشار صاحب السمو رئيس الدولة، رئيس اتحاد سباقات الهجن.",
               "news": "<div style=\"text-align: right;\">حضر سمو الشيخ منصور بن زايد آل نهيان نائب رئيس مجلس الوزراء وزير شؤون الرئاسة، مأدبة غداء أقامها لسموه معالي الشيخ سلطان بن حمدان بن محمد آل نهيان، مستشار صاحب السمو رئيس الدولة، رئيس اتحاد سباقات الهجن. حضر المأدبة الشيخ سعيد بن حمدان بن محمد آل نهيان، والشيخ خليفة بن سلطان بن حمدان آل نهيان، وعدد من الملاك من أبناء الدولة ودول مجلس التعاون الخليجي، وقدم الحضور التهنئة لسموه بمناسبة فوز إسطبلات الوثبة بكأس اليوم الوطني للقدرة، بعد إحراز الفارس علي يوسف الحمادي المركز الأول على ظهر الفرس (آرمور).<\/div>",
               "image": "http://www.prcamels.ae/images/news/npic92061215.jpg"
            }
         ]
      },
      {
         "section_title": "السباقات",
         "news": [
            {
               "news_date": "الأربعاء ، ١٩ مارس  ٢٠١٤",
               "news_title": "الوارية تنتزع سيف صاحب السمو رئيس الدولة",
               "news_summary": "أهدى معالي الشيخ سلطان بن حمدان آل نهيان مستشار صاحب السمو رئيس الدولة، رئيس اتحاد سباقات الهجن، إنجاز «هجن الرئاسة» وفوزها بسيفي الحول والزمول، وخنجر الزمول المحليات، إلى صاحب السمو الشيخ خليفة بن زايد آل نهيان رئيس الدولة حفظه الله،",
               "news": "<p align=\"right\">أهدى معالي الشيخ سلطان بن حمدان آل نهيان مستشار صاحب السمو رئيس الدولة، رئيس اتحاد سباقات الهجن، إنجاز «هجن الرئاسة» وفوزها بسيفي الحول والزمول، وخنجر الزمول المحليات، إلى صاحب السمو الشيخ خليفة بن زايد آل نهيان رئيس الدولة حفظه الله، مؤكداً أن فوز هجن الرئاسة بـ «ناموس القائد»، يمثل أعلى وأروع تكريم لمسيرة إنجازاتها المتلاحقة، التي توجتها أمس بتتويج مستحق واستثنائي، مشيراً إلى أن ما شهده المهرجان الختامي بالوثبة، يمثل شاهداً حياً على دعم وعطاء القيادة للرياضات التراثية، وفي مقدمتها سباقات الهجن التي تعيش عصرها الذهبي. <\/p><p align=\"right\">كما أهدى معاليه إنجاز «هجن الرئاسة» إلى الفريق أول سمو الشيخ محمد بن زايد آل نهيان ولي عهد أبوظبي نائب القائد الأعلى للقوات المسلحة، مشيداً بدعم سموه المتواصل للرياضة والرياضيين، وللرياضات التراثية بصفة خاصة، وفي مقدمتها سباقات الهجن، التي يحفظ منتسبوها لسموه أياديه البيضاء على هذه الرياضة، والتي تمثلت في عدة سباقات تطوف إمارات الدولة باسم سموه، إضافة إلى الدعم الدائم والسخي للسباقات في كل الميادين، ما جعل الإمارات وجهة للملاك والمضمرين من دول الخليج كافة. <\/p><p align=\"right\">وثمن معالي الشيخ سلطان بن حمدان آل نهيان مستشار صاحب السمو رئيس الدولة، رئيس اتحاد سباقات الهجن، دعم وعطاء سمو الشيخ منصور بن زايد آل نهيان، نائب رئيس مجلس الوزراء وزير شؤون الرئاسة، مؤكداً أن عطاء سموه بلا حدود، وأن ما شهدته سباقات الهجن ومختلف الرياضات التراثية من تطور، كان نتاجاً لأفكار سموه الوثابة التي لا تحدها حدود، وتنطلق من حب عميق للوطن، ومن ربط رائع بين الماضي بموروثه العريق والحاضر بمعطيات التطور، تطلعاً إلى مستقبل حافل بإذن الله لدولتنا الناهضة. <br><\/p>",
               "image": "http://www.prcamels.ae/images/news/npic18711720.jpg"
            },
            {
               "news_date": "الأحد ، ١٦ مارس  ٢٠١٤",
               "news_title": "الخفيفة لـ «هجن الرئاسة» تتصدر منافسات الشيوخ للثنايا",
               "news_summary": "شهد معالي الشيخ سلطان بن حمدان بن محمد آل نهيان مستشار صاحب السمو رئيس الدولة حفظه الله، رئيس اتحاد سباقات الهجن، منافسات اليوم السادس للمهرجان الختامي السنوي لسباقات الهجن بمنطقة الوثبة بالعاصمة أبوظبي",
               "news": "<div style=\"text-align: right;\">شهد معالي الشيخ سلطان بن حمدان بن محمد آل نهيان مستشار صاحب السمو رئيس الدولة حفظه الله، رئيس اتحاد سباقات الهجن، منافسات اليوم السادس للمهرجان الختامي السنوي لسباقات الهجن بمنطقة الوثبة بالعاصمة أبوظبي، والتي خصصت لسن (الثنايا) الطفح ولمسافة 6 كلم، كما شهد المنافسات، جمهور غفير من محبي رياضة سباقات الهجن من أبناء الدولة وإخوانهم من دول مجلس التعاون الخليجي.<\/div><div style=\"text-align: right;\"><br><\/div><div style=\"text-align: right;\">وتصدرت (الخفيفة) لهجن الرئاسة مع المضمر مبارك أحمد مطر الخييلي الشوط الأول والمخصص للبكار المحليات وأحرزت المركز الأول والناموس بعد أن قطعت مسافة الشوط في توقيت (9:15:2 دقيقة)، وجاءت في المركز الثاني (احتلال) لهجن الرئاسة والمضمر عيسى أحمد مطر الخييلي بتوقيت وقدره(9:17:2)، وحلت ثالثة (الوجبة) لهجن الشحانية والمضمر سالم فاران المري بتوقيت (9:20:00).<\/div><div style=\"text-align: right;\"><br><\/div>",
               "image": "http://www.prcamels.ae/images/news/npic27449365.jpg"
            }
         ]
      }
   ]
}

I want to load data of the first array section from this JSON code and display all arrays within that array plus there is a link to image file which I want to display as well. what will be the best approach to display that data along with the picture, please note that the data will be displayed within a scroll view or advice the best possible way to show the data other than scroll view because there are other elements on that page and only half of the acclivity size is available for this data.

The following data will be displayed from the JSON array:

News_Date
News_Title
News_Summary

I want to cover 20% of the Area with Picture and 80% with the Text in A Row and for each item the rows will be repeated.
 

eps

Expert
Licensed User
Longtime User
I suspect that Donmanfred is hoping that by having the id, the images can be loaded out of order.. Which could work.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
no, just wanted to know the right name to saved it to... Coming back to open my eyes... In the url i have the filename... Snippet GetFilename included and now i have the right name to save the image to.
But that is fixed. See code, comments (and video! :D) in #100
 
Last edited:
Upvote 0

Shahid Saeed

Active Member
Licensed User
Longtime User
See attachment... Actually it is a little bit flickering... but it works. and its late here. Tomorrow i can have a look again...

TRY TO UNDERSTAND IN THIS CODE WHAT HAPPEN AT THE VARIOUS STAGES PLEASE

http://snapshots.basic4android.de/Shahid.wmv
Really great work @DonManfred , Currently the code is going over my head, maybe i am sleepy too. I will put more energy in the morning, but i guess the listview text and height limit is blocking most of the text. Can it be fixed or we should try using CustomListview? Customlistview code is also not as easy as it was for listview without image. I hope so in the morning I can finish news potion and move to pictures and videos sections. Just one question is there a way to put slide show of these downloaded pictures? in my activity I have One imageview which is mainly the portion for pictures slideshow and than there is the list view. A likewise example is attached.
 

Attachments

  • screen568x568.jpeg
    screen568x568.jpeg
    38 KB · Views: 222
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
You have two lines (labels) on each listviewitem. or one if you just use this layout.

Anyway: with both labels you can change a lot of things...

try to have a look at the properties of

B4X:
lv.TwoLinesLayout.Label.Height = 25dip
lv.TwoLinesLayout.SecondLabel.Height = 25dip
' Instead of .height there are more possibilities.

BUT NOTE: You can change the line1+2 always for the HOLE LIST. If you set height to 100dip then the height is 100dip for each item.

Edit: just tried it with 100dip but seems not to work... maybe i do something wrong but that did not work... :-/

B4X:
lv.Initialize("lv")
lv.TwoLinesLayout.ItemHeight = 100dip
lv.TwoLinesLayout.Label.Height = 40dip
lv.TwoLinesLayout.Label.TextColor = Colors.Blue
lv.TwoLinesLayout.Label.TextSize = 20
lv.TwoLinesLayout.SecondLabel.Height = 60dip
lv.TwoLinesLayout.SecondLabel.TextColor = Colors.Red
lv.TwoLinesLayout.SecondLabel.TextSize = 10

TwoLinesLayout.ItemHeight seems to have no effect!? The item are still 40dip approx...

But i´m out now. It´s midnight in a few minutes and i have to stand up at 6am. So, i have to go to bed :)
 
Last edited:
Upvote 0

eps

Expert
Licensed User
Longtime User
Oops, sorry work got in the way (pesky thing!)..

Trying to work out why a SOAP request won't quite work.. hmm...

Definitely time for bed!
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
@Shahid Saeed, you can use @DonManfred's last attachment and separate that routines in the JobDone out to separate sub routines. Once the JobDone is successful, instead of processing the data in JobDone itself, you can call a subroutine to process the results for you. That way it will be easier for you to follow what is going on in his code.

I know that you started off by processing the actual JSON feed in the JobDone sub, but I personally never do that mainly for tidiness and ease of tracking my processes.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Once the JobDone is successful, instead of processing the data in JobDone itself, you can call a subroutine to process the results for you. That way it will be easier for you to follow what is going on in his code.

I have splitted up the things a little bit.

See new Code

It´s now without the flickering :)
Instead of showing a lot of Progressdialogues it uses a small label to show how many jobs are there...


Still missing are more comments in code. I´ll do that this evening if you need, @Shahid Saeed
 

Attachments

  • listviewandimages.zip
    7.4 KB · Views: 252
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
@DonManfred, thats excellent. I know that you only continued where @Shahid Saeed started. I was going to mention it to him before hand, but then you had already integrated the images and text colours ect in the code. So I thought that I would give him a hint thus making his life easier, especially if he is learning to a time limit. He might as well learn good practices now rather than later.
 
Upvote 0

Shahid Saeed

Active Member
Licensed User
Longtime User
@DonManfred, thats excellent. I know that you only continued where @Shahid Saeed started. I was going to mention it to him before hand, but then you had already integrated the images and text colours ect in the code. So I thought that I would give him a hint thus making his life easier, especially if he is learning to a time limit. He might as well learn good practices now rather than later.

Long hectic day to visit the client to inquire about more modification into the Application, Really Got busted more than 8 hours in Traveling, Just reached Office now. I am ready to take a look What @DonManfred has done for my, I really appreciate his and @eps & @Peter Simpson efforts to give me a kick start to finish it up.

@DonManfred I was thinking one thing, and need your help to see the possibility. Is there any possibility that I keep JSON file in Assets folder and when the App starts it checks if the device is connected with Internet and Update the JSON file from server into the Assets folders. In case if I keep using the file from server it might not load the news until the device will connect to the Internet. What are the possible ways to do that. because the iPhone and iPad apps are doing same thing if no Internet connection they will load the news from assets folder and display it and images are already cached for updated JSON file. One more thing I want to share is that the iPhone App loads the News Text Immediately and then instead of picture there is loader animation which moves until the picture got loaded.

Now I will go through your last code and until than I am sure you will have plenty of options to implement. :)
 
Upvote 0

Shahid Saeed

Active Member
Licensed User
Longtime User
I have splitted up the things a little bit.

See new Code

It´s now without the flickering :)
Instead of showing a lot of Progressdialogues it uses a small label to show how many jobs are there...


Still missing are more comments in code. I´ll do that this evening if you need, @Shahid Saeed

Before we were using this code to retrieve news from first section only.

B4X:
Dim parser As JSONParser
        parser.Initialize(NewsJson)
       
    Dim root As Map = parser.NextObject
    Dim news_sections As List = root.Get("news_sections")
   
    Dim bob As Int = 0
    For Each colnews_sections As Map In news_sections
   
        LogColor(bob, Colors.red)
       
        'Dim section_title As String = colnews_sections.Get("section_title")
        Dim news As List = colnews_sections.Get("news")

This is the code from your example and I guess it is loading news from All sections?

B4X:
Dim parser As JSONParser
    parser.Initialize(json)
    Dim root As Map = parser.NextObject
    Dim news_sections As List = root.get("news_sections")

    For Each colnews_sections As Map In news_sections
     'Dim section_title As String = colnews_sections.Get("section_title")
     Dim news As List = colnews_sections.get("news")

Should I include this code to your example to limit the news to first section (0) only?

B4X:
Dim bob As Int = 0
    For Each colnews_sections As Map In news_sections
   
        LogColor(bob, Colors.red)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I cannot read arabic characters. So i cannot READ what i show in app.

I would say my code lists ALL News from the FIRST section. After first section is finished an exit will break the loop. So, only the first section is handled in this code.

Maybe your JSON is wrong and shows up more news then there should be?

B4X:
For Each colnews_sections As Map In news_sections
	  'Dim section_title As String = colnews_sections.Get("section_title")
	  Dim news As List = colnews_sections.get("news")

	  For Each colnews As Map In news ' Lists all news in this section
	  	Dim news_date As String = colnews.get("news_date")
	    Dim news_title As String = colnews.get("news_title")
	    Dim news_summary As String = colnews.get("news_summary")
	    Dim news_image As String = colnews.get("image")       
	    'ToastMessageShow(news_image, True)
	    'Dim news1 As String = colnews.Get("news")
	    'Log(news_title)
	    'For i = 0 To colnews.Size -1
	    Dim filename As String
			filename = GetFileName(news_image)
			If File.Exists(File.DirDefaultExternal,filename) Then
				Dim bmp As Bitmap
				bmp.Initialize(File.DirDefaultExternal,filename)
				lv.AddTwoLinesAndBitmap(news_date&": "&news_title,news_summary,bmp)
			Else
				lv.AddTwoLines(news_date&": "&news_title,news_summary)
			End If
			
	    'Log(news_image)
		  'Log(news_title)
	  Next
	Exit 'EXIT HERE... Section is finished.. Out of the loop...
	Next
 
Upvote 0
Top