2011-10-24 5 views
1

Android 용 RSS 리더에서 작업 중이며 메뉴 항목을 추가 할 때 문제가 발생했습니다. 수동으로 피드를 새로 고치는 항목을 만들고 싶지만 "Menu.Item을 유형으로 확인할 수 없습니다."라는 오류가 발생합니다. 오류는 여기에 있습니다 :Android가 해결할 수없는 메뉴 항목

public boolean onOptionsItemSelected(Menu.Item item){ 
    switch (item.getId()) { 
    case 0: 

     Log.i(tag,"Set RSS Feed"); 
     return true; 
    case 1: 
     Log.i(tag,"Refreshing RSS Feed"); 
     return true; 
    } 
    return false; 
} 

전체 클래스는 여기에 있습니다 :

package com.CalvaryChapelMelbourne.feedparser; 


import android.app.Activity; 
import android.os.Bundle; 
import android.view.*; 
import android.widget.TextView; 
import android.widget.ListView; 
import android.widget.AdapterView; 
import android.widget.ListAdapter; 
import android.widget.ArrayAdapter; 
import android.widget.AdapterView.OnItemClickListener; 
import android.util.Log; 
import java.util.ArrayList; 
import java.net.URL; 

import javax.xml.parsers.SAXParser; 
import javax.xml.parsers.SAXParserFactory; 

import org.xml.sax.InputSource; 

import org.xml.sax.XMLReader; 

import android.content.Intent; 

import com.CalvaryChapelMelbourne.feedparser.ShowDescription; 

public class RSSReader extends Activity implements OnItemClickListener 
{ 

public final String RSSFEEDOFCHOICE = "http://app.calvaryccm.com/mobile/android/v1/devos"; 

public final String tag = "RSSReader"; 
private RSSFeed feed = null; 

/** Called when the activity is first created. */ 

public void onCreate(Bundle icicle) { 
    super.onCreate(icicle); 
    setContentView(R.layout.main); 

    // go get our feed! 
    feed = getFeed(RSSFEEDOFCHOICE); 

    // display UI 
    UpdateDisplay(); 

} 


private RSSFeed getFeed(String urlToRssFeed) 
{ 
    try 
    { 
     // setup the url 
     URL url = new URL(urlToRssFeed); 

     // create the factory 
     SAXParserFactory factory = SAXParserFactory.newInstance(); 
     // create a parser 
     SAXParser parser = factory.newSAXParser(); 

     // create the reader (scanner) 
     XMLReader xmlreader = parser.getXMLReader(); 
     // instantiate our handler 
     RSSHandler theRssHandler = new RSSHandler(); 
     // assign our handler 
     xmlreader.setContentHandler(theRssHandler); 
     // get our data via the url class 
     InputSource is = new InputSource(url.openStream()); 
     // perform the synchronous parse   
     xmlreader.parse(is); 
     // get the results - should be a fully populated RSSFeed instance, or null on error 
     return theRssHandler.getFeed(); 
    } 
    catch (Exception ee) 
    { 
     // if we have a problem, simply return null 
     return null; 
    } 
} 
public boolean onCreateOptionsMenu(Menu menu) 
{ 
    super.onCreateOptionsMenu(menu); 

    menu.add(0,0,"Choose RSS Feed"); 
    menu.add(0,1,"Refresh"); 
    Log.i(tag,"onCreateOptionsMenu"); 
    return true; 
} 

public boolean onOptionsItemSelected(Menu.Item item){ 
    switch (item.getId()) { 
    case 0: 

     Log.i(tag,"Set RSS Feed"); 
     return true; 
    case 1: 
     Log.i(tag,"Refreshing RSS Feed"); 
     return true; 
    } 
    return false; 
} 


private void UpdateDisplay() 
{ 
    TextView feedtitle = (TextView) findViewById(R.id.feedtitle); 
    TextView feedpubdate = (TextView) findViewById(R.id.feedpubdate); 
    ListView itemlist = (ListView) findViewById(R.id.itemlist); 


    if (feed == null) 
    { 
     feedtitle.setText("No RSS Feed Available"); 
     return; 
    } 

    feedtitle.setText(feed.getTitle()); 
    feedpubdate.setText(feed.getPubDate()); 

    ArrayAdapter<RSSItem> adapter = new ArrayAdapter<RSSItem>(this,android.R.layout.simple_list_item_1,feed.getAllItems()); 

    itemlist.setAdapter(adapter); 

    itemlist.setOnItemClickListener(this); 

    itemlist.setSelection(0); 

} 


public void onItemClick(AdapterView parent, View v, int position, long id) 
{ 
    Log.i(tag,"item clicked! [" + feed.getItem(position).getTitle() + "]"); 

    Intent itemintent = new Intent(this,ShowDescription.class); 

    Bundle b = new Bundle(); 
    b.putString("title", feed.getItem(position).getTitle()); 
    b.putString("description", feed.getItem(position).getDescription()); 
    b.putString("link", feed.getItem(position).getLink()); 
    b.putString("pubdate", feed.getItem(position).getPubDate()); 

    itemintent.putExtra("android.intent.extra.INTENT", b); 

    startSubActivity(itemintent,0); 
} 

} 

여러분의 도움에 감사드립니다!

답변

2

Menu.Item을 변경할 필요가 없습니다. 단순히 점을 제거하면 이동하는 것이 좋습니다.

2

MenuItem하지 Menu.Item해야한다 :

public boolean onOptionsItemSelected(MenuItem item){ 
2

당신은 Menu.Item, onOptionsItemSelected의 첫 번째 매개 변수의 MenuItem해야 MenuItem