Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7069277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:25:34+00:00 2026-05-28T05:25:34+00:00

Just a disclaimer, I’m very new to both android and Java. The end product

  • 0

Just a disclaimer, I’m very new to both android and Java.

The end product that I’m going after in this is a soundboard like application. I want to display a list of sounds that the user can tap on to play the associated sound file.

So far I have setup a couple of string-arrays in my strings.xml file. One array represents the sounds available, and the second array represents the actual R.raw.soundfile resources. Might be easier to just show it.

<string-array name="alex_list">
    <item>Sound Title</item>
</string-array>

<string-array name="alex_sounds">
    <item>R.raw.soundfile</item>
</string-array>

Here is the class definition I have so far. I really don’t want anyone to “do the work for me” as it were, but I’m completely lost as to where to progress from here. I feel like I should pass the string-array position from alex_list (when clicked) to get the right resource from alex_sounds (which should play immediately, doesn’t need media controls). But that’s where I get stuck.

public class AlexList extends ListActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setListAdapter(ArrayAdapter.createFromResource(getApplicationContext(), R.array.alex_list, R.layout.list_item));

    getListView().setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
            // I have zero clue what to do from here
        }

    });

}
}

If there is a better way to do any of this, please tell me. The last thing I want to do is develop bad habits at an early stage. I’ll continue to work on it and post back if I find a solution.

Thanks in advance for your time!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:25:35+00:00Added an answer on May 28, 2026 at 5:25 am

    Change your values array this way:

    <string-array name="alex_sounds">
        <item>soundfile</item>
    </string-array>
    

    Then your listener becomes: (packageName is a string representing the package of your R file: e.g. "com.example.main")

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
        String selectedFromList = getItemAtPosition(pos);
        int resId = getResources().getIdentifier(selectedFromList, "raw", packageName);
        MediaPlayer mp = MediaPlayer.create(AlexList.this, resId);  
        mp.start();
    }
    

    This will play the file which name you selected in your list view, from your res/raw folder.
    (Coded quickly in StackOverflow, there may be syntax errors)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

[Disclaimer] I am very new to Haskell (and any FPL for that matter), just
Disclaimer: I'm not very good at Java and just comparing read/writer locks between C#
Disclaimer: I'm new to unit testing and just getting my feet wet. That being
Disclaimer: I'm new to most of this I just downloaded virtualbox yesterday and installed
(Disclaimer: I am a C# guy. I've just started learning Clojure.) I understand that
Disclaimer, I not do anything in particular with regards this question, just curious. Is
Just for the disclaimer, I'm not trying to win the prize in Android Developer
[Disclaimer: I am new to PHP, and I am just learning, so please no
Disclaimer: this is needed for an old and ugly codebase that I'd much rather
DISCLAIMER: This is not a real-world example. It is just a theoretical question of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.