對於android編程來說是新鮮事物,並且在單擊按鈕時無法更改字符串值「channel」。嘗試關閉onCreate時出現問題,但似乎只能讓我在活動結束時關閉它。我收到「令牌」}「的錯誤。請刪除'如果我嘗試在其他地方關閉它。儘管這可能非常簡單,但我仍然很難將這個問題包括在內。在OnClick中更改字符串值
public class MainActivity extends Activity {
String channel = "bbc1";
// This method creates main application view
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set view
setContentView(R.layout.main);
final ViewSwitcher switcher = (ViewSwitcher)findViewById(R.id.ViewSwitcher1);
Button bbcButton = (Button) findViewById(R.id.bbcButton);
Button bbc2Button = (Button) findViewById(R.id.bbc2Button);
bbcButton.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
channel = "bbc1";
switcher.showNext();
}
});
bbc2Button.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
channel = "bbc2";
switcher.showNext();
}
});
try{
// This line creates RSS reader
RssReader rssReader = new RssReader("http://bleb.org/tv/data/rss.php?ch="+channel+"&day=0");
// This line gets a ListView from main view
ListView tvItems = (ListView) findViewById(R.id.listMainView);
// This line creates a list adapter
ArrayAdapter<RssItem> adapter = new ArrayAdapter<RssItem>(this,android.R.layout.simple_list_item_1, rssReader.getItems());
// This line sets list adapter for the ListView
tvItems.setAdapter(adapter);
} catch (Exception e) {
Log.e("Tv RSS Reader", e.getMessage());
}
}
}
從您發佈的代碼中,一切似乎都很好。最後的兩個結束'}'是'onCreate'方法,另一個是類。我對代碼進行了格式化,以便您可以更好地看到它。 – 2013-04-08 13:42:46
嘗試複製完整的代碼,刪除代碼並粘貼代碼。 CTRL + A,CTRL + C,CTRL + A,DELETE,Ctrl + V。 – 2013-04-08 13:46:05