1. Download our Official Android App: Forums for Android!

How to call webview class in intent?

Discussion in 'Android Development' started by catchappkiran, Sep 3, 2017.

  1. catchappkiran

    catchappkiran Newbie
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    20
    Joined:
    Sep 3, 2017

    Sep 3, 2017
    20
    1
    16
    WebView Class:

    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;

    import static android.provider.ContactsContract.CommonDataKinds.Website.URL;

    public class WebViewClass extends AppCompatActivity {

    private WebView webView;

    @override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_web_view_class);

    webView = (WebView) findViewById(R.id.webview);
    webView.setWebViewClient(new MyWebViewClient());
    webView.getSettings().setJavaScriptEnabled(true);
    String URL = "";
    webView.loadUrl(URL);
    }
    private class MyWebViewClient extends WebViewClient {
    @override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
    view.loadUrl(url);
    return true;
    }
    }
    }

    ================

    Intent intent = new Intent(this,WebViewClass.class); >> Here it is showing an error
    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(rssObject.getItems().get(posistion).getLink()));
    browserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
    mContext.startActivity(browserIntent);

    Link, URL getting from Uri.parse(rssObject.getItems().get(posistion).getLink())

    Can you please help

     

    Advertisement

  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,459
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,459
    10,744
    1,988
    Male
    Software developer
    South West of England
    What's the error?
     
  3. catchappkiran

    catchappkiran Newbie
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    20
    Joined:
    Sep 3, 2017

    Sep 3, 2017
    20
    1
    16
    Error:---- can't resolve symbol 'webviewclass'
     
  4. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,459
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,459
    10,744
    1,988
    Male
    Software developer
    South West of England
    So where is this code? in which class is it located? Did you import the WebViewClass.

    Code (Text):
    1.  
    2. Intent intent = new Intent(this,WebViewClass.class); >> Here it is showing an error
    3. Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(rssObject.getItems().get(posistion).getLink()));
    4. browserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
    5. mContext.startActivity(browserIntent);
    6.  
     
  5. catchappkiran

    catchappkiran Newbie
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    20
    Joined:
    Sep 3, 2017

    Sep 3, 2017
    20
    1
    16
    I will share my screen... can you help me to resolve this issue
     
  6. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,459
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,459
    10,744
    1,988
    Male
    Software developer
    South West of England
    Sure, but please answer my question. That bit of code I quoted is just floating. Which class is it part of? Please include more of the code so we can establish the context of it.
     
  7. catchappkiran

    catchappkiran Newbie
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    20
    Joined:
    Sep 3, 2017

    Sep 3, 2017
    20
    1
    16
    Intent code in different class (FeedAdapter):

    package com.catchappkiran.andriodrssfeed.Adapter;

    import android.content.Context;
    import android.content.Intent;

    import android.net.Uri;
    import android.support.v7.widget.RecyclerView;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;

    import android.widget.TextView;

    import com.catchappkiran.andriodrssfeed.Interface.ItemClickListener;
    import com.catchappkiran.andriodrssfeed.Model.RSSObject;
    import com.catchappkiran.andriodrssfeed.R;

    class FeedViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener,View.OnLongClickListener{

    public TextView txtTitle, txtPubDate, txtContent;
    private ItemClickListener itemClickListener;


    public FeedViewHolder(View itemView) {
    super(itemView);

    txtTitle = (TextView) itemView.findViewById(R.id.txtTitle);
    txtPubDate = (TextView) itemView.findViewById(R.id.txtPubDate);
    txtContent = (TextView) itemView.findViewById(R.id.txtContent);

    //Set Event
    itemView.setOnClickListener(this);
    itemView.setOnLongClickListener(this);

    }

    public ItemClickListener getItemClickListener() {
    return itemClickListener;
    }

    public void setItemClickListener(ItemClickListener itemClickListener) {
    this.itemClickListener = itemClickListener;
    }

    @override
    public void onClick(View v) {
    itemClickListener.onClick(v,getAdapterPosition(), false);

    }

    @override
    public boolean onLongClick(View v) {
    itemClickListener.onClick(v,getAdapterPosition(), true);
    return true;
    }
    }


    public class FeedAdapter extends RecyclerView.Adapter<FeedViewHolder> {

    private RSSObject rssObject;
    private Context mContext;
    private LayoutInflater inflater;

    public FeedAdapter(RSSObject rssObject, Context mContext) {
    this.rssObject = rssObject;
    this.mContext = mContext;
    inflater = LayoutInflater.from(mContext);
    }


    public FeedViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View itemView = inflater.inflate(R.layout.row,parent,false);
    return new FeedViewHolder(itemView);
    }


    public void onBindViewHolder(FeedViewHolder holder, int position){
    holder.txtTitle.setText(rssObject.getItems().get(position).getTitle());
    holder.txtPubDate.setText(rssObject.getItems().get(position).getPubDate());
    holder.txtContent.setText(rssObject.getItems().get(position).getContent());

    holder.setItemClickListener(new ItemClickListener() {

    public void onClick(View view, int position, boolean isLongClick) {
    if (!isLongClick){
    Intent intent = new Intent(this,webviewClass.class);
    //intent.putExtra("RSS_Link",rssObject.getItems().get(posistion).getLink());
    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(rssObject.getItems().get(position).getLink()));
    browserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
    mContext.startActivity(browserIntent);
    }
    }
    });

    }

    public int getItemCount(){
    return rssObject.items.size();
    }
    }
     
    #7 catchappkiran, Sep 4, 2017
    Last edited: Sep 4, 2017
  8. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,459
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,459
    10,744
    1,988
    Male
    Software developer
    South West of England
    Java is case sensitive. so

    Code (Text):
    1.  
    2. Intent intent = new Intent(this,webviewClass.class);
    3.  
    Is not the same as

    Code (Text):
    1.  
    2. Intent intent = new Intent(this,WebViewClass.class);
    3.  
    which I think is what you need to use.
     
  9. catchappkiran

    catchappkiran Newbie
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    20
    Joined:
    Sep 3, 2017

    Sep 3, 2017
    20
    1
    16
    Intent intent = new Intent(this,webviewClass.class); > this is correct. I am using this
     
  10. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,459
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,459
    10,744
    1,988
    Male
    Software developer
    South West of England
    But you said

     
  11. catchappkiran

    catchappkiran Newbie
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    20
    Joined:
    Sep 3, 2017

    Sep 3, 2017
    20
    1
    16
    Oh, this I have replied from App (AndroidForum). (Error:---- can't resolve symbol 'webviewclass')

    Intent intent = new Intent(this,webviewClass.class); > this is correct. I am using this
     
  12. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,459
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,459
    10,744
    1,988
    Male
    Software developer
    South West of England
    Just answer 'yes' or 'no' to the following question:

    Does changing this line

    Code (Text):
    1.  
    2. Intent intent = new Intent(this,webviewClass.class);
    3.  
    to this:

    Code (Text):
    1.  
    2. Intent intent = new Intent(this,WebViewClass.class);
    3.  
    make the problem go away?
     
  13. catchappkiran

    catchappkiran Newbie
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    20
    Joined:
    Sep 3, 2017

    Sep 3, 2017
    20
    1
    16
    Can I share the screen? Will discuss
     
  14. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,459
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,459
    10,744
    1,988
    Male
    Software developer
    South West of England
    Post a screenshot then.
     
  15. catchappkiran

    catchappkiran Newbie
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    20
    Joined:
    Sep 3, 2017

    Sep 3, 2017
    20
    1
    16
    webviewClass

    package com.catchappkiran.andriodrssfeed;

    import android.net.Uri;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;

    import android.webkit.WebView;
    import android.webkit.WebViewClient;

    public class webviewClass extends AppCompatActivity {
    private WebView webView;

    @override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_webview_class);

    webView = (WebView) findViewById(R.id.webview);
    setContentView(webView);
    webView.setWebViewClient(new myWebClient());
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl("how to call the url from FeedAdapter.java");
    }
    public class myWebClient extends WebViewClient
    {
    @override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
    view.loadUrl(url);
    return true;

    }
    }


    }

    FeedAdapter

    package com.catchappkiran.andriodrssfeed.Adapter;

    import android.content.Context;
    import android.content.Intent;

    import android.net.Uri;
    import android.support.v7.widget.RecyclerView;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;

    import android.widget.TextView;

    import com.catchappkiran.andriodrssfeed.Interface.ItemClickListener;
    import com.catchappkiran.andriodrssfeed.Model.RSSObject;
    import com.catchappkiran.andriodrssfeed.R;

    class FeedViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener,View.OnLongClickListener{

    public TextView txtTitle, txtPubDate, txtContent;
    private ItemClickListener itemClickListener;


    public FeedViewHolder(View itemView) {
    super(itemView);

    txtTitle = (TextView) itemView.findViewById(R.id.txtTitle);
    txtPubDate = (TextView) itemView.findViewById(R.id.txtPubDate);
    txtContent = (TextView) itemView.findViewById(R.id.txtContent);

    //Set Event
    itemView.setOnClickListener(this);
    itemView.setOnLongClickListener(this);

    }

    public ItemClickListener getItemClickListener() {
    return itemClickListener;
    }

    public void setItemClickListener(ItemClickListener itemClickListener) {
    this.itemClickListener = itemClickListener;
    }

    @override
    public void onClick(View v) {
    itemClickListener.onClick(v,getAdapterPosition(), false);

    }

    @override
    public boolean onLongClick(View v) {
    itemClickListener.onClick(v,getAdapterPosition(), true);
    return true;
    }
    }


    public class FeedAdapter extends RecyclerView.Adapter<FeedViewHolder> {

    private RSSObject rssObject;
    private Context mContext;
    private LayoutInflater inflater;

    public FeedAdapter(RSSObject rssObject, Context mContext) {
    this.rssObject = rssObject;
    this.mContext = mContext;
    inflater = LayoutInflater.from(mContext);
    }

    @override
    public FeedViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View itemView = inflater.inflate(R.layout.row,parent,false);
    return new FeedViewHolder(itemView);
    }

    @override
    public void onBindViewHolder(FeedViewHolder holder, int position){
    holder.txtTitle.setText(rssObject.getItems().get(position).getTitle());
    holder.txtPubDate.setText(rssObject.getItems().get(position).getPubDate());
    holder.txtContent.setText(rssObject.getItems().get(position).getContent());

    holder.setItemClickListener(new ItemClickListener() {
    @override
    public void onClick(View view, int position, boolean isLongClick) {
    if (!isLongClick){
    Intent intent = new Intent(this,webviewClass.class);
    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(rssObject.getItems().get(position).getLink()));
    browserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
    mContext.startActivity(browserIntent);
    }
    }
    });

    }
    @override
    public int getItemCount(){
    return rssObject.items.size();
    }
    }

    Finally i want to open url in webview
     
  16. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,459
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,459
    10,744
    1,988
    Male
    Software developer
    South West of England
    Sorry, I've just lost track of this.

    So can you please clarify what your current problem is?
     
  17. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,459
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,459
    10,744
    1,988
    Male
    Software developer
    South West of England
    And, for the love of God, please put your code in [code][/code] tags, and format it nicely.
     
  18. catchappkiran

    catchappkiran Newbie
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    20
    Joined:
    Sep 3, 2017

    Sep 3, 2017
    20
    1
    16
    Currently the url opening in browser.

    I want to open the url in webview. This is the problem. How to do that. ?
    webviewClass
    Code (Text):
    1.  
    2.  
    3. package com.catchappkiran.andriodrssfeed;
    4.  
    5. import android.net.Uri;
    6. import android.support.v7.app.AppCompatActivity;
    7. import android.os.Bundle;
    8.  
    9. import android.webkit.WebView;
    10. import android.webkit.WebViewClient;
    11.  
    12. public class webviewClass extends AppCompatActivity {
    13. private WebView webView;
    14.  
    15. [USER=1021285]@override[/USER]
    16. protected void onCreate(Bundle savedInstanceState) {
    17. super.onCreate(savedInstanceState);
    18. setContentView(R.layout.activity_webview_class);
    19.  
    20. webView = (WebView) findViewById(R.id.webview);
    21. setContentView(webView);
    22. webView.setWebViewClient(new myWebClient());
    23. webView.getSettings().setJavaScriptEnabled(true);
    24. webView.loadUrl("how to call the url from FeedAdapter.java");
    25. }
    26. public class myWebClient extends WebViewClient
    27. {
    28. [USER=1021285]@override[/USER]
    29. public boolean shouldOverrideUrlLoading(WebView view, String url) {
    30. view.loadUrl(url);
    31. return true;
    32.  
    33. }
    34. }
    35.  
    36.  
    37. }
    38.  
    FeedAdapter

    Code (Text):
    1.  
    2.  
    3. package com.catchappkiran.andriodrssfeed.Adapter;
    4.  
    5. import android.content.Context;
    6. import android.content.Intent;
    7.  
    8. import android.net.Uri;
    9. import android.support.v7.widget.RecyclerView;
    10. import android.view.LayoutInflater;
    11. import android.view.View;
    12. import android.view.ViewGroup;
    13.  
    14. import android.widget.TextView;
    15.  
    16. import com.catchappkiran.andriodrssfeed.Interface.ItemClickListener;
    17. import com.catchappkiran.andriodrssfeed.Model.RSSObject;
    18. import com.catchappkiran.andriodrssfeed.R;
    19.  
    20. class FeedViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener,View.OnLongClickListener{
    21.  
    22. public TextView txtTitle, txtPubDate, txtContent;
    23. private ItemClickListener itemClickListener;
    24.  
    25.  
    26. public FeedViewHolder(View itemView) {
    27. super(itemView);
    28.  
    29. txtTitle = (TextView) itemView.findViewById(R.id.txtTitle);
    30. txtPubDate = (TextView) itemView.findViewById(R.id.txtPubDate);
    31. txtContent = (TextView) itemView.findViewById(R.id.txtContent);
    32.  
    33. //Set Event
    34. itemView.setOnClickListener(this);
    35. itemView.setOnLongClickListener(this);
    36.  
    37. }
    38.  
    39. public ItemClickListener getItemClickListener() {
    40. return itemClickListener;
    41. }
    42.  
    43. public void setItemClickListener(ItemClickListener itemClickListener) {
    44. this.itemClickListener = itemClickListener;
    45. }
    46.  
    47. @override
    48. public void onClick(View v) {
    49. itemClickListener.onClick(v,getAdapterPosition(), false);
    50.  
    51. }
    52.  
    53. @override
    54. public boolean onLongClick(View v) {
    55. itemClickListener.onClick(v,getAdapterPosition(), true);
    56. return true;
    57. }
    58. }
    59.  
    60.  
    61. public class FeedAdapter extends RecyclerView.Adapter<FeedViewHolder> {
    62.  
    63. private RSSObject rssObject;
    64. private Context mContext;
    65. private LayoutInflater inflater;
    66.  
    67. public FeedAdapter(RSSObject rssObject, Context mContext) {
    68. this.rssObject = rssObject;
    69. this.mContext = mContext;
    70. inflater = LayoutInflater.from(mContext);
    71. }
    72.  
    73. @override
    74. public FeedViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    75. View itemView = inflater.inflate(R.layout.row,parent,false);
    76. return new FeedViewHolder(itemView);
    77. }
    78.  
    79. @override
    80. public void onBindViewHolder(FeedViewHolder holder, int position){
    81. holder.txtTitle.setText(rssObject.getItems().get(position).getTitle());
    82. holder.txtPubDate.setText(rssObject.getItems().get(position).getPubDate());
    83. holder.txtContent.setText(rssObject.getItems().get(position).getContent());
    84.  
    85. holder.setItemClickListener(new ItemClickListener() {
    86. @override
    87. public void onClick(View view, int position, boolean isLongClick) {
    88. if (!isLongClick){
    89. Intent intent = new Intent(this,webviewClass.class);
    90. Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(rssObject.getItems().get(position).getLink()));
    91. browserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
    92. mContext.startActivity(browserIntent);
    93. }
    94. }
    95. });
    96.  
    97. }
    98. @override
    99. public int getItemCount(){
    100. return rssObject.items.size();
    101. }
    102. }
    103.  
     
  19. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,459
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,459
    10,744
    1,988
    Male
    Software developer
    South West of England

Share This Page

Loading...