Search code examples
javaandroideclipseonclickfragmentmanager

Web Link using DialogFragment


I have this dialog fragment, but i'm trying to get it so that when a user clicks on the "My Other Apps" Button they get redirected to a web address. Is there any way of doing this. Any help is appreciated Thanks

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // TODO Auto-generated method stub

    AlertDialog.Builder theDialog = new AlertDialog.Builder(getActivity());
    theDialog.setTitle("About");
    String d1 = "Thanks For Downloading! ";
    String d2 = "Made by ME";
    theDialog.setMessage(d1 +"\n"+ d2 ); 
    theDialog.setPositiveButton("My Other Apps", new DialogInterface.OnClickListener(){


        @Override
        public void onClick(DialogInterface dialog, int which) {
            Toast.makeText(getActivity(), "Clicked My Other Apps",
                    Toast.LENGTH_SHORT).show();

        }

    });

    theDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener(){

        @Override
        public void onClick(DialogInterface dialog, int which) {
            Toast.makeText(getActivity(), "Clicked Cancel",
                    Toast.LENGTH_SHORT).show();

        }

    });     
    return theDialog.create();
  }
}       

Solution

  • @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    
    AlertDialog.Builder theDialog = new AlertDialog.Builder(getActivity());
    theDialog.setTitle("About");
    String d1 = "Thanks For Downloading! ";
    String d2 = "Made by ME";
    theDialog.setMessage(d1 +"\n"+ d2 ); 
    theDialog.setPositiveButton("My Other Apps", new DialogInterface.OnClickListener(){
    
    
    @Override
    public void onClick(DialogInterface dialog, int which) {
        String url = "http://www.example.com";
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        startActivity(i);
    
    }
    
    });
    
    theDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener(){
    
    @Override
    public void onClick(DialogInterface dialog, int which) {
        Toast.makeText(getActivity(), "Clicked Cancel",
        Toast.LENGTH_SHORT).show();
    
    }
    
    });     
    return theDialog.create();
    }
    }