嗨我想讓我的列表視圖與每個部分打開不同的活動。截至目前,我可以開展一項活動,但他們都開放相同的活動。我需要知道改變,例如:Android ListView-開始與每個項目的新活動
item1將打開activity1 item2將打開activity2等等。
任何幫助將非常感激,這裏是我的代碼(一些評論的是形成一個教程,我跟着我的經驗不足很抱歉):
ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
//get listview from xml
listView = (ListView)findViewById(R.id.listView);
//defined array to show in listview
String[] values = new String[]{"About the App",
"How to Use",
"Build log",
};
//define a new context
//First parameter - Context
// Second parameter - Layout for the row
// Third parameter - ID of the TextView to which the data is written
// Forth - the Array of data
ArrayAdapter<String>adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, values);
//Assign adapter to listview
listView.setAdapter(adapter);
// ListView Item Click Listener
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
/*//listview clicked item index
int itemPosition = position;
//Listview clicked item value
String itemValue = (String)listView.getItemAtPosition(position);
//show alert
Toast.makeText(getApplicationContext(),
"Position:"+itemPosition+" ListItem:" + itemValue, Toast.LENGTH_LONG).show();*/
Intent appInfo = new Intent(About.this, about_app.class);
startActivity(appInfo);
}
});
}
非常感謝你的幫助:D – 2015-04-06 06:51:25
@noobvenvonhack謝謝 – 2015-04-06 06:52:28