• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

How to call webview class in intent?

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
 
So where is this code? in which class is it located? Did you import the WebViewClass.

Code:
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);
 
So where is this code? in which class is it located? Did you import the WebViewClass.

<br>

<br>

<div style='margin: 1em auto' title='Code'>

<ol class='text' style='font-family:monospace;'>

<li style='font-weight: normal; vertical-align:top;'>

<div style='font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;'>

 

</div></li>

<li style='font-weight: normal; vertical-align:top;'>

<div style='font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;'>

Intent intent = new Intent(this,WebViewClass.class); >> Here it is showing an error

</div></li>

<li style='font-weight: normal; vertical-align:top;'>

<div style='font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;'>

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(rssObject.getItems().get(posistion).getLink()));

</div></li>

<li style='font-weight: normal; vertical-align:top;'>

<div style='font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;'>

browserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);

</div></li>

<li style='font-weight: bold; vertical-align:top;'>

<div style='font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;'>

mContext.startActivity(browserIntent);

</div></li>

<li style='font-weight: normal; vertical-align:top;'>

<div style='font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;'>

 

</div></li>

</ol>

</div>
I will share my screen... can you help me to resolve this issue
 
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.
 
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();
}
}
 
Last edited:
Java is case sensitive. so

Code:
Intent intent = new Intent(this,webviewClass.class);

Is not the same as

Code:
Intent intent = new Intent(this,WebViewClass.class);

which I think is what you need to use.
 
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
 
Just answer 'yes' or 'no' to the following question:

Does changing this line

Code:
Intent intent = new Intent(this,webviewClass.class);

to this:

Code:
Intent intent = new Intent(this,WebViewClass.class);

make the problem go away?
 
Just answer 'yes' or 'no' to the following question:

&lt;br&gt;

&lt;br&gt; Does changing this line

&lt;br&gt;

&lt;br&gt;

&lt;div style='margin: 1em auto' title='Code'&gt;

&lt;ol class='text' style='font-family:monospace;'&gt;

&lt;li style='font-weight: normal; vertical-align:top;'&gt;

&lt;div style='font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;'&gt;

&amp;nbsp;

&lt;/div&gt;&lt;/li&gt;

&lt;li style='font-weight: normal; vertical-align:top;'&gt;

&lt;div style='font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;'&gt;

Intent intent = new Intent(this,webviewClass.class);

&lt;/div&gt;&lt;/li&gt;

&lt;li style='font-weight: normal; vertical-align:top;'&gt;

&lt;div style='font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;'&gt;

&amp;nbsp;

&lt;/div&gt;&lt;/li&gt;

&lt;/ol&gt;

&lt;/div&gt;to this:

&lt;br&gt;

&lt;br&gt;

&lt;div style='margin: 1em auto' title='Code'&gt;

&lt;ol class='text' style='font-family:monospace;'&gt;

&lt;li style='font-weight: normal; vertical-align:top;'&gt;

&lt;div style='font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;'&gt;

&amp;nbsp;

&lt;/div&gt;&lt;/li&gt;

&lt;li style='font-weight: normal; vertical-align:top;'&gt;

&lt;div style='font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;'&gt;

Intent intent = new Intent(this,WebViewClass.class);

&lt;/div&gt;&lt;/li&gt;

&lt;li style='font-weight: normal; vertical-align:top;'&gt;

&lt;div style='font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;'&gt;

&amp;nbsp;

&lt;/div&gt;&lt;/li&gt;

&lt;/ol&gt;

&lt;/div&gt;make the problem go away?
Can I share the screen? Will discuss
 
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
 
Sorry, I've just lost track of this.

So can you please clarify what your current problem is?
 
And, for the love of God, please put your code in [code][/code] tags, and format it nicely.
 
Currently the url opening in browser.

I want to open the url in webview. This is the problem. How to do that. ?
webviewClass
Code:
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;

[USER=1021285]@override[/USER]
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
{
[USER=1021285]@override[/USER]
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;

}
}


}

FeedAdapter

Code:
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();
}
}
 
Back
Top Bottom