I want make a soundboard. For this i have make a listview with a xml file (for the name and the sound).
For first, i have make a listview with the title of the sound. When we click on it, the sound is played.
NB : I didn't have change somes name like gridView, don't worry i use a listview.
MainActivity:
mSoundPlayer = new SoundPlayer(this); Sound[] soundArray = SoundStore.getSounds(this); ListView gridView = (ListView) findViewById(R.id.gridView); final ArrayAdapter<Sound> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, soundArray); gridView.setAdapter(adapter); gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { Sound sound = (Sound) parent.getItemAtPosition(position); mSoundPlayer.playSound(sound); } }); I use a xml file for indexing the name of sounds and the sounds.
File : arrays.xml :
<?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="labels"> <item>First sound</item> <item>Second soung</item> </string-array> <integer-array name="ids"> <item>@raw/a1</item> <item>@raw/a2</item> </integer-array> </resources> And for the last, my layout :
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="0dp" android:paddingRight="0dp" android:paddingTop="0dp" android:paddingBottom="0dp" tools:context="com.clemb.sardboard.MainActivity"> <ListView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gridView" android:numColumns="auto_fit" android:gravity="center" android:columnWidth="100dp" android:verticalSpacing="5dp" android:stretchMode="columnWidth" android:layout_width="fill_parent" android:layout_height="fill_parent"/> </RelativeLayout> I just want to know how add a picture before the name of the sound. And can i do it in my array.xml ?
Thank you.
No comments:
Post a Comment