我是Java和Android的新手,我想知道是否可以在案例中使用Intent
來創建一個新的背景,然後顯示用戶點擊的項目的文本(例如,他們點擊打開的聯繫人,然後告訴他們什麼是開放聯繫人)或者有其他方法嗎?Android switch語句錯誤
public class ListActivityExample extends ListActivity{
static final String[] ACTIVITY_CHOICES = new String[] {
"Open Website Example",
"Open Contacts",
"Open Phone Dialer Example",
"Search Google Example",
"Start Voice Command"
};
final String searchTerms = "superman";
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, ACTIVITY_CHOICES));
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
getListView().setTextFilterEnabled(true);
getListView().setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3){
switch(arg2) {
case 0: //opens web browser and navigates to given website
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://ww.android.com")));
break;
case 1: //opens phone dialer and fills in the given number
{
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("content://contacts/people/")));
break;}
case 2:
{
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("tel:12125551212")));
break;}
case 3: //
{
Intent intent= new Intent(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY, searchTerms);
startActivity(intent);
break;}
case 4: //
{startActivity(new
Intent(Intent.ACTION_VOICE_COMMAND));
break;}
default: break;
}
}
});
}
}
究竟是什麼錯誤/不在您提供的示例代碼中工作? – 2011-02-14 17:59:29
它完美的作品,我只是想改變底部的情況下,所以當單擊列表活動時,它會帶來一個新的屏幕與每個案件的文字。 – dfair 2011-02-14 18:30:40