Hey everyone I am new to Android programming and need some Help. I have a list view that consists of HashMap objects. These hashMap objects can be selected by checking a check box. (So basically I have a check box list). What I am trying to do is Store all the HashMap objects (or items) that are checked in the ListView in an ArrayList. I then want to Pass this arrayList to another activity when a button is pressed. I've seen some examples of people storing string data but I need some help on how I would store "checked" HashMap objects in a listView into an ArrayList. So at the end all I want is an ArrayList that consists of objects (items) that were checked in the list which I can then pass.
What program goal is: allow user to select songs based on category and create their own custom playlist. The user will be presented songs for one category, they will select the songs they want from that category and then push a "Next" button which will send them to a new activity where they will be presented a new category of songs. At each category I am trying to store their selection and pass it along from activity(category) to activity(category). But the passing is not working. I could be doing something way off. Need some advice what or how to do. -Thanx
some code: Not the most organized I know. New to android so any pointers or things I should change
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.playlist);
//final ArrayList<HashMap<String, String>> songsListData = new ArrayList<HashMap<String, String>>();
SongsManager plm = new SongsManager();
// get all songs from sdcard
this.songsList = plm.getPlayList();
TextView label = new TextView(this);
label.setText("Warm-up");
label.setTextSize(16);
label.setBackgroundColor(Color.WHITE);
label.setTextColor(Color.BLACK);
final ArrayList<HashMap<String, String>> songsListData = new ArrayList<HashMap<String, String>>();
// looping through playlist
for(HashMap hs: songsList){
if(hs.containsValue("Warm-up/cool down"))
songsListData.add(hs);
}
// NEXT button
Button btnLoadMore = new Button(this);
btnLoadMore.setText("Next");
ListView lv = getListView();
lv.addHeaderView(label);
// Adding Load More button to lisview at bottom
lv.addFooterView(btnLoadMore);
//List<Model> selectedlist = getModel(songsListData);
ArrayAdapter<Model> adapter = new InteractiveArrayAdapter(this,
getModel(songsListData));
setListAdapter(adapter);
//Listening to Load More button click event
btnLoadMore.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
String priorSongs = "priorSongs";
List<Model> selSongs = getModel(songsListData);
Intent i = new Intent(WarmUp.this, SlowWalking.class);
i.putExtra(priorSongs, selSongs);
startActivity(i);
}
});
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
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(),
AndroidBuildingMusicPlayerActivity.class);
in.putExtra("songIndex", songIndex);
startActivity(in);
finish();
}
});
}
private List<Model> getModel(ArrayList<HashMap<String, String>> songsListData) {
List<Model> list = new ArrayList<Model>();
for (HashMap<String, String> map : songsListData)
for (Entry<String, String> entry : map.entrySet())
if (entry.getKey() == "songTitle")
list.add(get(entry.getValue()));
// Initially select one of the items
//list.get(1).setSelected(true);
return list;
}