Click here to Skip to main content
15,560,576 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am developing an rss feeds using recyclerview, the part am finding difficult to crack is
how to make the each rss item click load in a webview when user clicks it. Is always showing blank when clicked
kindly look at the code below

public class MyRecyclerAdapter extends RecyclerView.Adapter<myrecycleradapter.customviewholder> {
private List<feeditem> feedItemList;
private Context mContext;

private String URL_KEY;

public MyRecyclerAdapter(Context context, List<feeditem> feedItemList) {
this.feedItemList = feedItemList;
this.mContext = context;
}

@Override
public CustomViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_row, null);

CustomViewHolder viewHolder = new CustomViewHolder(view);
return viewHolder;
}

@Override
public void onBindViewHolder(CustomViewHolder customViewHolder, int i) {
FeedItem feedItem = feedItemList.get(i);

//Download image using picasso library
Picasso.with(mContext).load(feedItem.getThumbnail())
.error(R.mipmap.ic_launcher)
.placeholder(R.mipmap.ic_launcher)
.into(customViewHolder.imageView);

//Setting text view title
customViewHolder.textView.setText(Html.fromHtml(feedItem.getTitle()));

//Handle click event on both title and image click
customViewHolder.textView.setOnClickListener(clickListener);
customViewHolder.imageView.setOnClickListener(clickListener);

customViewHolder.textView.setTag(customViewHolder);
customViewHolder.imageView.setTag(customViewHolder);
}

@Override
public int getItemCount() {
return (null != feedItemList ? feedItemList.size() : 0);
}

public class CustomViewHolder extends RecyclerView.ViewHolder {
protected ImageView imageView;
protected TextView textView;

public CustomViewHolder(View view) {
super(view);
this.imageView = (ImageView) view.findViewById(R.id.thumbnail);
this.textView = (TextView) view.findViewById(R.id.title);
}
}

View.OnClickListener clickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
CustomViewHolder holder = (CustomViewHolder) view.getTag();
int position = holder.getPosition();

FeedItem feedItem = feedItemList.get(position);
Toast.makeText(mContext, feedItem.getTitle(), Toast.LENGTH_SHORT).show();

Intent intent = new Intent(mContext.getApplicationContext(), Details.class);
intent.putExtra("url", feedItem.getUrl());
mContext.startActivity(intent);

/*String urlval = link + "";
Intent mIntent = new Intent(mContext.getApplicationContext(), Details.class);
mIntent.putExtra(Details.URL_KEY, urlval);
mContext.startActivity(mIntent);*/

}
};
}

WEBVIEW ACTIVITY

public class Details extends ActionBarActivity {

public static String URL_KEY;
private android.webkit.WebView webView1;
private String title;
private String url;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);

//title = getIntent().getExtras().getString("title");
//url = getIntent().getExtras().getString("url");


getSupportActionBar().setTitle(title);

if (savedInstanceState != null) {
((android.webkit.WebView) findViewById(R.id.webView1)).restoreState(savedInstanceState);
} else {

webView1 = (android.webkit.WebView) findViewById(R.id.webView1);
webView1.getSettings().setJavaScriptEnabled(true);
webView1.getSettings().setBuiltInZoomControls(true);
webView1.setLayerType(View.LAYER_TYPE_SOFTWARE, null);


final Activity activity = this;


webView1.setWebViewClient(new WebViewClient()

{
@Override
public boolean shouldOverrideUrlLoading(android.webkit.WebView view,
String url) {
// TODO Auto-generated method stub
view.loadUrl(url);
return true;
}
});

webView1.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(android.webkit.WebView view, int progress) {
// Activities and WebViews measure progress with different scales.
// The progress meter will automatically disappear when we reach 100%
activity.setProgress(progress * 1000);
}
});

webView1.setWebViewClient(new WebViewClient() {
public void onReceivedError(android.webkit.WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
});



runOnUiThread(new Runnable() {
@Override
public void run() {
// Code for WebView goes here
webView1.loadUrl(url);
}
});

/*Bundle extras = getIntent().getExtras();
String url = extras.getString(URL_KEY);
webView1.loadUrl(url);*/

Bundle bundle = this.getIntent().getExtras();
String url = bundle.getString("url");
if (null != url) {
webView1.loadUrl(url);
}


}
}

What I have tried:

I tried searching it on stackoverflow and asking posting the question on gdg
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900