我的应用程序在列表视图中的android应用程序中显示rss提要,用于过滤我在activity_main_content.xml中创建EditText的数据 我需要过滤rssFeed标题内容的帮助。另外我还附上了我的rss feed java文件
rssitem.java
import android.text.Html;
import java.io.Serializable;
/**
* This class is used to remember rss item data
*/
public class RSSItem implements Serializable {
private String title = null;
private String description = null;
private String rowdescription = null;
private String link = null;
private String pubdate = null;
private String thumburl = null;
private String audiourl = null;
private String videourl = null;
void setTitle(String value) {
title = value;
}
void setDescription(String value) {
description = value;
rowdescription = stripHtml(value).toString();
}
void setLink(String value) {
link = value;
}
void setPubdate(String value) {
pubdate = value;
}
void setThumburl(String value) {
thumburl = value;
}
void setVideourl(String value) {
videourl = value;
}
void setAudiourl(String value) {
audiourl = value;
}
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
public String getRowDescription() {
return rowdescription;
}
public String getLink() {
return link;
}
public String getPubdate() {
return pubdate;
}
public String getAudiourl() {
return audiourl;
}
public String getVideourl() {
return videourl;
}
public String getThumburl() {
return thumburl;
}
public CharSequence stripHtml(String s) {
return Html.fromHtml(s).toString().replace('\n', (char) 32)
.replace((char) 160, (char) 32).replace((char) 65532, (char) 32).trim();
}
}
rssfeed.java
import java.util.List;
import java.util.Vector;
/**
* This class is used to save information about our rss feed
*/
public class RSSFeed {
private String title = null;
private String description = null;
private String link = null;
private String pubdate = null;
private List<RSSItem> itemList;
RSSFeed(){
itemList = new Vector<RSSItem>(0);
}
void addItem(RSSItem item){
itemList.add(item);
}
public RSSItem getItem(int location){
return itemList.get(location);
}
public List<RSSItem> getList(){
return itemList;
}
void setTitle(String value)
{
title = value;
}
void setDescription(String value)
{
description = value;
}
void setLink(String value)
{
link = value;
}
void setPubdate(String value)
{
pubdate = value;
}
public String getTitle()
{
return title;
}
public String getDescription()
{
return description;
}
public String getLink()
{
return link;
}
String getPubdate()
{
return pubdate;
//This is not formatted, as formatting might be different for every feed
}
}
RSSadapter.java
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.sherdle.universal.R;
import com.sherdle.universal.providers.rss.ui.RssDetailActivity;
import com.sherdle.universal.providers.rss.ui.RssFragment;
import com.sherdle.universal.util.InfiniteRecyclerViewAdapter;
import com.sherdle.universal.util.ViewModeUtils;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Target;
import java.util.List;
public class RssAdapter extends InfiniteRecyclerViewAdapter {
private List<RSSItem> objects;
private Context context;
private static int COMPACT = 0;
private static int NORMAL = 1;
private ViewModeUtils viewModeUtils;
public RssAdapter(Context context,
List<RSSItem> list) {
super(context, null);
this.context = context;
this.objects = list;
this.viewModeUtils = new ViewModeUtils(context, RssFragment.class);
}
@Override
public int getViewType(int position) {
if (viewModeUtils.getViewMode() == ViewModeUtils.NORMAL)
return NORMAL;
else
return COMPACT;
}
@Override
protected RecyclerView.ViewHolder getViewHolder(ViewGroup parent, int viewType) {
if (COMPACT == viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.fragment_rss_row, parent, false);
return new RssViewHolder((itemView));
} else if (viewType == NORMAL) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.listview_row, parent, false);
return new RssLargeViewHolder(itemView);
}
return null;
}
@Override
protected void doBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
if (viewHolder instanceof RssViewHolder){
RssViewHolder holder = (RssViewHolder) viewHolder;
String html = objects.get(position).getRowDescription();
holder.listTitle.setText(objects.get(position).getTitle());
holder.listPubdate.setText(objects.get(position).getPubdate());
holder.listDescription.setText(html);
holder.listThumb.setImageDrawable(null);
String thumburl = objects.get(position).getThumburl();
loadImageIntoView(thumburl, holder.listThumb);
setOnClickListener(holder.itemView, position);
} else {
RssLargeViewHolder itemHolder = (RssLargeViewHolder) viewHolder;
itemHolder.headlineView.setText(objects.get(position).getTitle());
itemHolder.reportedDateView.setText(objects.get(position).getPubdate());
itemHolder.imageView.setImageBitmap(null);
String thumburl = objects.get(position).getThumburl();
loadImageIntoView(thumburl, itemHolder.imageView);
setOnClickListener(itemHolder.itemView, position);
}
}
private void setOnClickListener(View view, final int position){
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context,
RssDetailActivity.class);
Bundle bundle = new Bundle();
intent.putExtra(RssDetailActivity.EXTRA_RSSITEM, objects.get(position));
intent.putExtras(bundle);
context.startActivity(intent);
}
});
}
private void loadImageIntoView(String thumburl, final ImageView listThumb){
if (thumburl != null && !thumburl.equals("")) {
//setting the image
final ImageView imageView = listThumb; // The view Picasso is loading an image into
final Target target = new Target() {
@Override
public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) {
/* Save the bitmap or do something with it here */
if (10 > bitmap.getWidth() || 10 > bitmap.getHeight()) {
// handle scaling
listThumb.setVisibility(View.GONE);
} else {
listThumb.setVisibility(View.VISIBLE);
listThumb.setImageBitmap(bitmap);
}
}
@Override
public void onBitmapFailed(Exception e, Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
};
imageView.setTag(target);
Picasso.get()
.load(thumburl)
.into(target);
} else {
listThumb.setVisibility(View.GONE);
}
}
@Override
protected int getCount() {
return objects.size();
}
private class RssViewHolder extends RecyclerView.ViewHolder {
TextView listTitle;
TextView listPubdate;
TextView listDescription;
ImageView listThumb;
RssViewHolder(View view){
super(view);
this.listTitle = view.findViewById(R.id.listtitle);
this.listPubdate = view.findViewById(R.id.listpubdate);
this.listDescription = view.findViewById(R.id.shortdescription);
this.listThumb = view.findViewById(R.id.listthumb);
}
}
private static class RssLargeViewHolder extends RecyclerView.ViewHolder {
TextView headlineView;
TextView reportedDateView;
ImageView imageView;
RssLargeViewHolder(View view){
super(view);
this.headlineView = view.findViewById(R.id.title);
this.reportedDateView = view.findViewById(R.id.date);
this.imageView = view.findViewById(R.id.thumbImage);
}
}
}
我希望根据字符串标题过滤rss内容,应该在main_acitivity.java中进行更改