0
我在我的XML文件中創建了ListView
,但我想從我的ListView
上的項目打開一個新屏幕。如何從列表視圖中打開新屏幕
我知道我必須使用OnItemClickListener
但我不知道我必須做什麼。 有人可以幫我嗎?
我ListView
在Java中:
package com.example.listentomusic;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
public class March extends Activity {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.march);
ListView list = (ListView) findViewById(R.id.listView1);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View viewClicked, int position, long id) {
// TODO Auto-generated method stub
startActivity(new Intent("android.intent.action.ABOUT"));
}
});
}
}
我ListView
在XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/standaard_background" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/maart"
android:textSize="30sp"
android:textColor="#FFFFFF"
android:background="#000000" />
<android.support.v7.widget.Space
android:id="@+id/space1"
android:layout_width="fill_parent"
android:layout_height="15dp" />
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/songs_march"
android:textColor="#FFFFFF" >
</ListView>
</LinearLayout>
我的字符串數組:
<string-array name="songs_march">
<item >1. p!nk - just give me a reason </item>
<item >2. Bingo Players - Get Up </item>
<item >3. macklemore - thrift shop </item>
<item >4. troublemaker - olly murs </item>
<item >5. Netsky - We Can Only Live Today </item>
<item >6. Dj F.R.A.N.K Feat. Miss Autumn Leaves - Yes You Run </item>
<item >7. labyrinth – beneath your beautiful </item>
<item >8. Nicole Scherzinger - Boomerang </item>
<item >9. DJ Fresh - Gold Dust </item>
<item >10. Justin Timberlake - suit and tie </item>
<item >11. cascada – glorious </item>
<item >12. DJ Fresh ft Sian Evans - Louder</item>
<item >13. DJ Fresh ft. Rita Ora - Hot Right Now</item>
<item >14. one direction - kiss you </item>
<item >15. Coone - Headbanger </item>
<item >16. Alicia keys - girl on fire </item>
<item >17. Skream And Example - Shot Yourself In The Foot Again </item>
<item >18. Isaac - Ease My Mind</item>
<item >19. Headhunterz vs. Psyko Punkz - Disrespect</item>
<item >20. pitbull - feel this moment </item>
<item >21. Carrie Underwoods - Two Black Cadillac’s </item>
<item >22. Alicia keys - Brand New Me </item>
<item >23. Inna - More Than Friends</item>
<item >24. Freestylers - Cracks (Ft. Belle Humble)(Flux Pavilion Remix)</item>
<item >25. P!nk - Try</item>
<item >26. Hien - No More </item>
<item >27. Xilent - Boss Wave</item>
<item >28. Christina Aguilera - Just A Fool </item>
<item >29. Evol - Marina And The Diamond</item>
<item >30. Kesha - C mon</item>
<item >31. Matrix And Futurebound - Magnetic Eyes</item>
<item >32. Adele - Skyfall </item>
<item >33. Baauer - Harlem Shake</item>
<item >34. Mark With A K - Blow Your Brainz</item>
<item >35. One Direction - One Way Or Another </item>
<item >36. Calvin Harris - Drinking From The Bottle </item>
<item >37. Skrillex And Damian - Make It Bun Dem</item>
<item >38. Taylor Swift - I Knew You Were Trouble</item>
<item >39. Coone - Monstah</item>
<item >40. Kelly Clarson - Catch My Breath </item>
</string-array>
我已閱讀文章,但我不明白它爲我想要的 – ILikeAndroid 2013-04-21 22:07:12
請參閱第二個鏈接。你可以更具體的關於你想要打開的屏幕是一個新的活動或片段 – NickF 2013-04-22 07:15:36
我想他想以樹形式擴展一個列表,我說得對嗎? – Ankit 2013-04-22 17:56:40