如何在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);
}
}
}
}
}
`
非常感謝您! – Principiante
v檢查按鈕點擊我;) –