简体   繁体   English

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

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

Downloaded this Source Code: https://github.com/shikha14/ParsingRssFeeds 下载了此源代码: https : //github.com/shikha14/ParsingRssFeeds

I want to add more menu items, but it don´t work... 我想添加更多菜单项,但是不起作用...

The original code in 原始代码在

AppUtils.java 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";

and Api.java: 和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);
}

I try this: 我尝试这样:

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";

and this: 和这个:

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;
}

When i start the app, it display the 4 items, but the url work only for the first and second menu items... have anyone a idea? 当我启动该应用程序时,它显示4个项目,但该网址仅适用于第一个菜单项和第二个菜单项...有人知道吗?

Thanks for answers... 感谢您的回答...

Your code, in the question, has only two conditions: if (position == 0) and else . 在问题中,您的代码只有两个条件: if (position == 0)else You need to handle the additional positions. 您需要处理其他职位。 Also, in your 'else' block you assign the value of AppUtils.RSS_2 to the local variable url. 同样,在“ else”块中,将AppUtils.RSS_2的值分配给本地变量url。 Then you assign AppUtils.RSS_3 to url, which replaces the value that it previously referenced. 然后,将AppUtils.RSS_3分配给url,它将替换先前引用的值。 Then you repeat for AppUtils.RSS_4. 然后,重复AppUtils.RSS_4。 That won't achieve anything, since each of your assignments overwrote the effects of the previous one. 那将什么也做不了,因为您的每个作业都覆盖了上一个作业的效果。

Assuming you actually created the menu items (your question doesn't contain anything about that), then handle them: 假设您实际上创建了菜单项(您的问题不包含任何内容),然后进行处理:

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