Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8566049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:34:03+00:00 2026-06-11T17:34:03+00:00

I have develped an Android RSS reader.I have created a tab layout and created

  • 0

I have develped an Android RSS reader.I have created a tab layout and created each tab for each type of news(say Headlines,National,International etc).

Then I listed RSS title and its images in custom listview on the first page of tablayout.
see the image below.

enter image description here

Now when the user click on a news title, another activity(page) opens with the news description.

My problem is when a user clicks on a tab and when it loads, if the internet connection is not available I want to show a dialog box with two buttons, Retry & Exit.

When the user click Retry the activity should be reloaded.I used a method( if(International.Title==null) ).But I dont think its a right method to do this.I want to know if there is a better solution for checking whether the network is available….

Here is my code,

 public class International extends Activity {
    static final String URL = "http://www.abcd.com/en/taxonomy/term/3/0/feed";
    static final String KEY_HEAD = "item";
    static final String KEY_DATE = "pubDate";
    ListView list;
    InternationalAdapter adapter;

    public static String[] Title;
    public static String[] Description;
    public static String[] image;
    public static String[] Date;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.headlines);

        Bundle mybundle = new Bundle();
        mybundle.putString("number", "0");
        new DoInBackground().execute();
    }
    public void do_update() 
        {
            internationalparser.parse();//this is the function to parse RSS feeds

        }


    public void populate_listview()
     {

        ArrayList<HashMap<String, String>> newsList = new ArrayList<HashMap<String, String>>();

        XMLParser parser = new XMLParser();
        String xml = parser.getXmlFromUrl(URL); // getting XML from URL
        Document doc = parser.getDomElement(xml); // getting DOM element

        NodeList nl = doc.getElementsByTagName(KEY_HEAD);
        // looping through all song nodes <song>
        NodeList itemLst = doc.getElementsByTagName("item");


        for (int i = 0; i < nl.getLength(); i++) {
            // creating new HashMap
            HashMap<String, String> map = new HashMap<String, String>();
            Element e = (Element) nl.item(i);

            //map.put(KEY_DATE, parser.getValue(e, KEY_DATE));

            newsList.add(map);
        }


        list=(ListView)findViewById(R.id.list);

        // Getting adapter by passing xml data ArrayList
        adapter=new InternationalAdapter(this, newsList);        
        list.setAdapter(adapter);


        // Click event for single list row
        list.setOnItemClickListener(new OnItemClickListener() {


            public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
                Intent myintent = new Intent("com.abcd.rssreaderinternationalpodcast.PODCAST");
                Bundle mybundle = new Bundle();
                mybundle.putInt("number", position);
                myintent.putExtras(mybundle);

                startActivity(myintent);

            }

        }); 

    }


     private class DoInBackground extends AsyncTask<Void, Void, Void>
     implements DialogInterface.OnCancelListener
{   
private ProgressDialog dialog;
private Intent intent;
private Intent intent2;

public void onPreExecute() 
{

    dialog = ProgressDialog.show(International.this, "", "Loading", true);

}

protected Void doInBackground(Void... unused) 
{ 


do_update(); 
return null; 
}

public void retry()
{

    internationalparser.parse();
}

protected void onPostExecute(Void unused) 
{ 


    if(International.Title!=null)
    {

        dialog.dismiss();
        populate_listview();

    }
    if(International.Title==null) ///this is what I tried.
    {
        dialog.dismiss();
         AlertDialog.Builder alertbox = new AlertDialog.Builder(International.this);

          alertbox.setMessage("Error in connection!");
          alertbox.setPositiveButton("Retry", new DialogInterface.OnClickListener() {

             public void onClick(DialogInterface arg0, int arg1) {

               retry();             //here i want to reload  activity

             }

         });

         alertbox.setNegativeButton("Exit", new DialogInterface.OnClickListener() {


             public void onClick(DialogInterface arg0, int arg1) {

                 finish();

             }

         });

         alertbox.show();

    }

}

public void onCancel(DialogInterface dialog) 
{ 
cancel(true); 
dialog.dismiss(); 
  }
 }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:34:04+00:00Added an answer on June 11, 2026 at 5:34 pm

    This is my class for internet connection with retry/exit

    usage:

    URLContent httpContent = new URLContent(this);
    String test =  httpContent.getContent("http://www.hotmail.com/");
    

    class:

    import java.io.BufferedReader;
    
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.net.URI;
    
    
    import org.apache.http.HttpResponse;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.impl.client.DefaultHttpClient;
    
    import android.app.AlertDialog;
    import android.content.Context;
    import android.content.DialogInterface;
    import android.net.ConnectivityManager;
    import android.net.NetworkInfo;
    
    public class URLContent {
    
        MainActivity mMainActivity;
        String returnData;
        String address;
    
        public URLContent(MainActivity mMainActivity)  
        {
            this.mMainActivity = mMainActivity;
        }
    
    
        public String getContent(String address)
        {
            this.address = address;
            processContent(address);
            return returnData;
        }
    
        private void processContent(String address)
        {
    
            try {
    
                if (!isNetworkAvailable(mMainActivity))
                {
                    throw new Exception("No internet connectivity.");
                }
    
                HttpClient client = new DefaultHttpClient();
                HttpGet request = new HttpGet();
                request.setURI(new URI(address));
                HttpResponse response = client.execute(request);
    
                    if (response.getStatusLine().getStatusCode() == 200)
                    {
                        InputStream ips  = response.getEntity().getContent();
                        BufferedReader buf = new BufferedReader(new InputStreamReader(ips,"UTF-8"));
    
                        StringBuilder sb = new StringBuilder();
                        String s;
                        while(true)
                        {
                            s = buf.readLine();
                            if(s==null || s.length()==0)
                                break;
                            sb.append(s);
    
                        }
                        buf.close();
                        ips.close();
    
                        returnData = sb.toString();
                    }
                    else
                    {
                        throw new Exception();
                    }
    
            } catch (Exception e) {
    
                 makeAndShowDialogBox(e.getMessage()).show();
            }
    
        }
    
        private static boolean isNetworkAvailable(Context context) 
        {
           ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
           if (connectivity == null) 
           {
               return false;
           } else 
           {
              NetworkInfo[] info = connectivity.getAllNetworkInfo();
              if (info != null) 
              {
                 for (int i = 0; i < info.length; i++) 
                 {
                    if (info[i].getState() == NetworkInfo.State.CONNECTED) 
                    {
                       return true;
                    }
                 }
              }
           }
           return false;
        }
    
        private AlertDialog makeAndShowDialogBox(String msg)
        {
            AlertDialog myQuittingDialogBox =  new AlertDialog.Builder(mMainActivity) 
    
                .setCancelable(false)
                .setTitle(R.string.connectionerr) 
                .setMessage(msg) 
    
                .setPositiveButton("Retry", new DialogInterface.OnClickListener() { 
                    public void onClick(DialogInterface dialog, int whichButton) { 
                     //whatever should be done when answering "YES" goes here
                        getContent(address);
                    }              
                })//setPositiveButton
                .setNegativeButton("Exit", new DialogInterface.OnClickListener() { 
                    public void onClick(DialogInterface dialog, int whichButton) { 
                     //whatever should be done when answering "NO" goes here
                        mMainActivity.finish();
                 } 
                })//setNegativeButton
    
                .create();
    
                return myQuittingDialogBox;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed a Bengali fixed layout softkeyboard for android and now want to
I have developed an Andriod RSS reader app.I have used custom listview to list
I have developed a android application using phonegap. I have registered certain recievers which
I have developed and android Application and export as APK file to publish this
I have developed the android phonegap application using html page and css. But My
I have developed a UI for android 2.3. The UI contains a list, and
I have developed two apps for Android. I copy them to memory card of
I have developed a Service for Android that starts when BOOT_COMPLETED is received.It works
I have developed a kernel module (Android) which provides me: PCM 16-bit 48000 Hz
I have developed my app in android 2.2, and put it on google market

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.