繁体   English   中英

Java / Android FeedParser-再添加一个菜单项

[英]Java/Android FeedParser - Add one more Menu Item

下载了此源代码: https : //github.com/shikha14/ParsingRssFeeds

我想添加更多菜单项,但是不起作用...

原始代码在

AppUtils.java

public class AppUtils {

public static final String RSS_CNN_NEWS = "http://rss.cnn.com/rss/cnn_latest.rss";
public static final String RSS_GOOGLE_NEW = "https://news.google.com/?output=rss";
public static final String TAG = "DIGIPLUSE";

和Api.java:

 public void getNews(int position, FetchListener listener) {
    String url = null;
    if (position == 0) {
        url = AppUtils.RSS_CNN_NEWS;
    } else {
        url = AppUtils.RSS_GOOGLE_NEW;
    }
    new AsyncHTTPPost().execute(url, listener);
}

我尝试这样:

public class AppUtils {

public static final String RSS_1 = "http://example.org/feed&type=rss";
public static final String RSS_2 = "http://example.org/feed&type=rss";
public static final String RSS_3 = "http://example.org/feed&type=rss";
public static final String RSS_4 = "http://example.org/feed&type=rss";

和这个:

public void getNews(int position, FetchListener listener) {
String url = null;
if (position == 0) {
url = AppUtils.RSS_1;
} else {
url = AppUtils.RSS_2;
url = AppUtils.RSS_3;
url = AppUtils.RSS_4;
}

当我启动该应用程序时,它显示4个项目,但该网址仅适用于第一个菜单项和第二个菜单项...有人知道吗?

感谢您的回答...

在问题中,您的代码只有两个条件: if (position == 0)else 您需要处理其他职位。 同样,在“ else”块中,将AppUtils.RSS_2的值分配给本地变量url。 然后,将AppUtils.RSS_3分配给url,它将替换先前引用的值。 然后,重复AppUtils.RSS_4。 那将什么也做不了,因为您的每个作业都覆盖了上一个作业的效果。

假设您实际上创建了菜单项(您的问题不包含任何内容),然后进行处理:

if (position == 0) {
    url = AppUtils.RSS_1;
} else if (position == 1) {
    url = AppUtils.RSS_2;
} else if (position == 2) {
    url = AppUtils.RSS_3;
} else if (position == 3) {
    url = AppUtils.RSS_4;
} else {
    throw new IllegalArugmentException("Unrecognized position: "+position);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM