我正在开发 android 媒体播放器。在 main.java 它包含 main.xml 和 list.java 包含
list.xml ,我使用意图调用 list.java (当我按下 imagebutton 时)进入 main.java ,但是当我按下 imagebutton list.xml 出现新窗口我想要显示在 main.xml 的底部
在 main.java 图像按钮调用 list.java 到 main.java
songslist_button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(main.this, list.class);
Toast.makeText(main.this, "Song List", Toast.LENGTH_SHORT).show();
startActivityForResult(i, 100);
//Intent i = new Intent(main.this, list.class);
//startActivity(i);
}
});
/////////////////////////
public class list extends ListActivity
{
// Songs list
public ArrayList<HashMap<String, String>> songsLists = new ArrayList<HashMap<String, String>>();
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.list);//list.xml
ArrayList<HashMap<String, String>> songsListData = new ArrayList<HashMap<String, String>>();
SongList plm = new SongList();
// get all songs from sdcard
this.songsLists = plm.getPlayList();
// looping through playlist
for (int i = 0; i < songsLists.size(); i++)
{
// creating new HashMap
HashMap<String, String> song = songsLists.get(i);
// adding HashList to ArrayList
songsListData.add(song);
}
// Adding menuItems to ListView
ListAdapter adapter = new SimpleAdapter(this, songsListData,
R.layout.song_item, new String[] { "songTitle" }, new int[] {R.id.song_title });
setListAdapter(adapter);
// selecting single ListView item
ListView lv = getListView();
//lv = (ListView) findViewById (R.layout.list);
// listening to single listitem click
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,int position, long id)
{
// getting listitem index
int songIndex = position;
// Starting new intent
Intent in = new Intent(getApplicationContext(),main.class);
// Sending songIndex to PlayerActivity
in.putExtra("songIndex", songIndex);
setResult(100, in);
// Closing PlayListView
finish();
}
});
}
}