MainActivity.java と SongLoad.java があります。のコードMainActivity.java
は
public class MainActivity extends Activity {
public static final int LOADREQUEST = 100;
private String callerClass = "DoubleMode";
ImageButton loadPlaylist1,loadPlaylist2;
ImageButton play1,play2;
SongLoad songloader = new SongLoad(callerClass);
MusicPlayerService musicplayer = new MusicPlayerService();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.homescreen);
loadPlaylist1 = (ImageButton)findViewById(R.id.load_button1);
loadPlaylist2 = (ImageButton)findViewById(R.id.load_button2);
play1 = (ImageButton)findViewById(R.id.play1);
play2 = (ImageButton)findViewById(R.id.play2);
}
public void onLoad(View v) {
int loadButtonPressed = v.getId();
songloader.playListGenerator();
musicplayer.songLoader(songloader.songIndex, loadButtonPressed);.. soon
SongLoad.java
public class SongLoad extends ListActivity{
public int songIndex = 0;
public String selectedSongPath;
public String callerClass;
final String MEDIA_PATH = new String(Environment.getExternalStorageDirectory().getPath());
public ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();
ArrayList<HashMap<String, String>> songsListData = new ArrayList<HashMap<String, String>>();
SongLoad(String callerClass) {
this.callerClass = callerClass;
}
SongLoad() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
if(callerClass == "DoubleMode")
{
setContentView(R.layout.playlist);
}
}
public void playListGenerator() {
mediaScanner();
for (int i = 0; i < songsList.size(); i++) {
// creating new HashMap
HashMap<String, String> song = songsList.get(i);
// adding HashList to ArrayList
songsListData.add(song);
}
// Adding menuItems to ListView
ListAdapter adapter = new SimpleAdapter(this, songsListData,
R.layout.playlist_item, new String[] { "songTitle" }, new int[] {
R.id.songTitle });
setListAdapter(adapter);
// selecting single ListView item
ListView lv = getListView();
// listening to single listitem click
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
// getting listitem index
songIndex = position;
selectedSongPath = songsList.get(songIndex).get("songPath");
}
});
}
今私の質問は、SongLoad.java のオブジェクトを作成し、playListGenerator onCreate メソッドを呼び出すと呼び出されるということです。しかし、私はそれを実行したい。それ、どうやったら出来るの?