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

  • SEARCH
  • Home
  • 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 6785119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:05:12+00:00 2026-05-26T17:05:12+00:00

package com.VRG; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import android.app.Activity; import android.content.Context; import android.media.MediaPlayer;

  • 0
package com.VRG;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.content.Context;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class Practice extends Activity {
    MediaPlayer mp;
    private Integer prac_sounds[] = { R.raw.cow, R.raw.camel, R.raw.dog,
            R.raw.donkey, R.raw.elephant, R.raw.horse, R.raw.lion, R.raw.rhino,
            R.raw.sheep, R.raw.wolf, R.raw.crow, R.raw.dove, R.raw.duck,
            R.raw.eagle, R.raw.owl, R.raw.parrot, R.raw.rooster, R.raw.cuckoo,
            R.raw.peocock, R.raw.sparrow };

    /** Called when the activity is first created. */

    // I use HashMap arraList which takes objects

    private ArrayList<HashMap<String, Object>> myimages;

    private static final String IMAGEKEY = "imagename";
    private static final String PRICEKEY = "bookprice";

    private static final String IMGKEY = "Images from Drawable";

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.list);

        ListView listView = (ListView) findViewById(R.id.list);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> av, View v, int pos, long id) {

                Log.i("111111111111111111", "" + mp);
                // if ()

                if (mp != null) {
                    if (mp.isPlaying()) {
                        mp.stop();
                    }
                }
                mp = MediaPlayer.create(Practice.this, prac_sounds[pos]);
                mp.seekTo(0);
                mp.start();
                mp.setOnCompletionListener(new OnCompletionListener() {

                    @Override
                    public void onCompletion(MediaPlayer mpalmost) {
                        try {
                            mp.prepare();
                            Log.i("prepare", "during preparing");
                        } catch (IllegalStateException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        mp.reset();
                        Log.i("reset", "during resetting");
                        // mp = null;

                    }
                });
            }

        });

        myimages = new ArrayList<HashMap<String, Object>>();

        HashMap<String, Object> hm;

        hm = new HashMap<String, Object>();
        hm.put(IMAGEKEY, "cow");
        hm.put(IMGKEY, R.drawable.cow);
        myimages.add(hm);

        hm = new HashMap<String, Object>();
        hm.put(IMAGEKEY, "camel");
        hm.put(IMGKEY, R.drawable.camel);
        myimages.add(hm);

        hm = new HashMap<String, Object>();
        hm.put(IMAGEKEY, "dog");
        hm.put(IMGKEY, R.drawable.dog);
        myimages.add(hm);

        hm = new HashMap<String, Object>();
        hm.put(IMAGEKEY, "donkey");
        hm.put(IMGKEY, R.drawable.donkey);
        myimages.add(hm);

        hm = new HashMap<String, Object>();
        hm.put(IMAGEKEY, "elephant");
        hm.put(IMGKEY, R.drawable.elephant);
        myimages.add(hm);

        hm = new HashMap<String, Object>();
        hm.put(IMAGEKEY, "horse");
        hm.put(IMGKEY, R.drawable.horse);
        myimages.add(hm);

        hm = new HashMap<String, Object>();
        hm.put(IMAGEKEY, "lion");
        hm.put(IMGKEY, R.drawable.lion);
        myimages.add(hm);

        hm = new HashMap<String, Object>();
        hm.put(IMAGEKEY, "rhino");
        hm.put(IMGKEY, R.drawable.rhinos);
        myimages.add(hm);

        hm = new HashMap<String, Object>();
        hm.put(IMAGEKEY, "sheep");
        hm.put(IMGKEY, R.drawable.sheep);
        myimages.add(hm);

        hm = new HashMap<String, Object>();
        hm.put(IMAGEKEY, "wolf");
        hm.put(IMGKEY, R.drawable.wolf);
        myimages.add(hm);

        hm = new HashMap<String, Object>();
        hm.put(IMAGEKEY, "crow");
        hm.put(IMGKEY, R.drawable.crow);
        myimages.add(hm);

        hm = new HashMap<String, Object>();
        hm.put(IMAGEKEY, "dove");
        hm.put(IMGKEY, R.drawable.dove);
        myimages.add(hm);

        hm = new HashMap<String, Object>();
        hm.put(IMAGEKEY, "duck");
        hm.put(IMGKEY, R.drawable.duck);
        myimages.add(hm);

        hm = new HashMap<String, Object>();
        hm.put(IMAGEKEY, "eagle");
        hm.put(IMGKEY, R.drawable.eagle);
        myimages.add(hm);

        hm = new HashMap<String, Object>();
        hm.put(IMAGEKEY, "owl");
        hm.put(IMGKEY, R.drawable.owl);
        myimages.add(hm);

        hm = new HashMap<String, Object>();
        hm.put(IMAGEKEY, "parrot");
        hm.put(IMGKEY, R.drawable.parrot);
        myimages.add(hm);

        hm = new HashMap<String, Object>();
        hm.put(IMAGEKEY, "rooster");
        hm.put(IMGKEY, R.drawable.rooster);
        myimages.add(hm);

        hm = new HashMap<String, Object>();
        hm.put(IMAGEKEY, "cuckoo");
        hm.put(IMGKEY, R.drawable.cuckoo);
        myimages.add(hm);


        hm = new HashMap<String, Object>();
        hm.put(IMAGEKEY, "peocock");
        hm.put(IMGKEY, R.drawable.peocock);
        myimages.add(hm);

        hm = new HashMap<String, Object>();
        hm.put(IMAGEKEY, "sparrow");
        hm.put(IMGKEY, R.drawable.sparrow);
        myimages.add(hm);


        listView.setAdapter(new myListAdapter(myimages, this));

        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

        // listView.setStackFromBottom(false);

    }

    private class myListAdapter extends BaseAdapter {

        private ArrayList<HashMap<String, Object>> IMAGES;

        private LayoutInflater mInflater;

        public myListAdapter(ArrayList<HashMap<String, Object>> images,
                Context context) {

            IMAGES = images;

            mInflater = LayoutInflater.from(context);

        }

        @Override
        public int getCount() {

            return IMAGES.size();

        }

        @Override
        public Object getItem(int position) {

            return IMAGES.get(position);

        }

        @Override
        public long getItemId(int position) {

            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            ViewHolder holder;

            if (convertView == null) {

                convertView = mInflater.inflate(R.layout.listview, null);

                // Creates a ViewHolder and store references to the two children
                // views

                // we want to bind data to.
                holder = new ViewHolder();

                holder.v = (TextView) convertView.findViewById(R.id.text1);

                holder.v1 = (TextView) convertView.findViewById(R.id.text2);

                holder.icon = (ImageView) convertView.findViewById(R.id.img);

                // holder.rating =
                // (RatingBar)convertView.findViewById(R.id.star);

                convertView.setTag(holder);

            } else {

                // Get the ViewHolder back to get fast access to the TextView

                // and the ImageView.

                holder = (ViewHolder) convertView.getTag();

            }

            // Bind the data with the holder.

            holder.v.setText((String) IMAGES.get(position).get(IMAGEKEY));

            holder.v1.setText((String) IMAGES.get(position).get(PRICEKEY));

            holder.icon.setImageResource((Integer) IMAGES.get(position).get(
                    IMGKEY));

            return convertView;

        }

        class ViewHolder {

            TextView v;

            TextView v1;

            ImageView icon;

        }

    }

    public void onBackPressed() {
        Log.v("44444", "onBackPressed Called");
        if (mp != null) {
            if (mp.isPlaying()) {
                mp.stop();
            }

        }
        finish();

    }

    public void onKeyDown() {
        onBackPressed();

    }
}

Here is my list.xml:

android:orientation="vertical" android:layout_width="fill_parent"

android:layout_height="fill_parent">

<ListView android:layout_width="fill_parent"

    android:layout_height="fill_parent" android:id="@+id/list"/>

Here is my listview.xml:

android:layout_width="wrap_content" android:orientation="horizontal"

android:layout_height="wrap_content">

<LinearLayout android:layout_width="265dip"

    android:orientation="vertical" android:layout_height="wrap_content">

    <TextView android:layout_width="fill_parent"

        android:layout_height="wrap_content" android:id="@+id/text1"

        android:textSize="25dip" android:text="This is text1" />
    <ImageView android:layout_height="wrap_content" android:src="@drawable/speak" android:id="@+id/imageView1" android:layout_width="wrap_content"></ImageView>

    <TextView android:layout_width="fill_parent"

        android:id="@+id/text2"

        android:text="This is text2" android:layout_height="wrap_content"/>

</LinearLayout>

<ImageView android:layout_width="55dip"

    android:layout_height="fill_parent" android:id="@+id/img" />

Actually I am using one custom list view. In that I have animals, birds and some random images respectively. Now I need to give title to the categories of images. i.e i need to seperate the images according to the category by giving title in the list. Please do me a need ful. Here is my java coding:

  • 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-26T17:05:13+00:00Added an answer on May 26, 2026 at 5:05 pm

    Here is a complete example of using Section Header with a nice explanation as well. You can also download the source code and checkout how it works.

    UPDATE

    You can also see my blog post

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

Sidebar

Related Questions

package com.ustr.eMIRnew; import java.util.ArrayList; import java.util.HashMap; import android.R; import android.app.Activity; import android.os.Bundle; import android.widget.ListView;
package com.Project_recording; import java.io.File; import java.io.IOException; import android.app.Activity; import android.media.MediaPlayer; import android.media.MediaRecorder; import android.os.Bundle;
package com.rest; import java.io.IOException; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button;
package com.android.SMStest; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.telephony.SmsManager; import android.view.View; import android.widget.Button;
package com.example.helloandroid; import java.util.ArrayList; import java.util.Arrays; import android.app.TabActivity; import android.os.Bundle; import android.view.Window; import android.widget.ArrayAdapter;
package com.commonsware.android.layouts; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button; import java.util.Date; public class
package com.geoo; import android.app.Activity; import android.content.Context; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle;
package com.ebonybutler.cexample3; import android.app.Activity; import android.content.Intent; import android.content.pm.ActivityInfo; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener;
I have created following activity package com.ali.test; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import
I got the following code inside my templateApp.java: package com.android.templateApp; import android.app.Activity; import android.os.Bundle;

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.