2015-05-24 62 views
0

如何在Android Studio中打開在列表視圖中單擊項目的新活動?或者更確切地說 - 我只是一個問題。問題在代碼中描述。對不起我的英語不好!!! Here's代碼`如何在Android Studio中打開在列表視圖中單擊項目的新活動?

public class MainActivity extends Activity { 

ListView listView; 
ArrayAdapter<String> adapter; 
String[] android_versions= { "Jelly Bean", "Kitkat", "Donut", 
     "Eclair", "Froyo", "Honeycomb", "Ice Cream" 
     }; 

@Override 
protected void onCreate(Bundle savedInstanceState) 
{ 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    listView = (ListView)findViewById(R.id.list_view); 
    adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,android_versions); 
    listView.setAdapter(adapter); 
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
     @Override 
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 

     //Here´s the problem! The super.OnItemClick 
     //doesn´t work.// 


      super.OnItemClick(parent, view, position, id); 

     //Here´s the problem! The super. doesn´t work.// 

      if (position == 0) { 
       Intent intent = new Intent(this, JellyBean.class); 
       startActivity(intent); 
      } 
      else if (position == 1) { 
       Intent intent = new Intent(this, Kitkat.class); 
       startActivity(intent); 
      } 
      else if (position == 2) { 
       Intent intent = new Intent(this, Donut.class); 
       startActivity(intent); 
      } 
     } 
    } 
} 
} 

`

回答

1

刪除super.OnItemClick(父,查看,位置,ID);

Intent myIntent = new Intent(view.getContext(), JellyBean.class); 
startActivity(intent); 
+0

非常感謝您! – Principiante

+0

v檢查按鈕點擊我;) –

0

由於ItemClickListener接口,沒有super實現,這樣可以去除super.OnItemClick

+0

它幫助。非常感謝。 – Principiante

相關問題