列表视图中的onClick音频

时间:2016-02-03 14:48:35

标签: java android audio

您好Stackoverflow成员,

我已经制作了一个可扩展的列表视图,它在我的应用程序中完美运行,但我只是设法让它显示Toast onClick,我如何获得listview中的每个细节来播放音频?

这是我的适配器/ java代码...提前感谢任何建议..

  

Convo.java

package learn.navdrawbase;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class Convo extends Activity {
HashMap<String, List<String>> Movies_category;
    List<String> Movies_list;
    ExpandableListView Exp_list;
    MoviesAdapter adapter;
    public Integer i;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.trans_convo);
        Exp_list=(ExpandableListView) findViewById(R.id.exp_list);
        Movies_category = DataProvider.getInfo();
        Movies_list = new ArrayList<String>(Movies_category.keySet());
        adapter = new MoviesAdapter(this, Movies_category,  Movies_list);
        Exp_list.setAdapter(adapter);

        Exp_list.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
            @Override
            public void onGroupExpand(int groupPosition) {
                Toast.makeText(getBaseContext(),Movies_list.get(groupPosition)+ " is expanded",
                Toast.LENGTH_LONG).show();
            }
        });
        Exp_list.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
            @Override
            public void onGroupCollapse(int groupPosition) {
                Toast.makeText(getBaseContext(), Movies_list.get(groupPosition) + " is Collapsed ",
                        Toast.LENGTH_LONG).show();
            }
        });

        Exp_list.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
            @Override
            public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
                Toast.makeText(getBaseContext(),
                        Movies_category.get(Movies_list.get(groupPosition)).get(childPosition) + " from Category " +
                        Movies_list.get(groupPosition) + " is selected ", Toast.LENGTH_LONG).show();

                return true;
            }





        });
    }}
  

MoviesAdapter.java

import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import java.util.HashMap;
import java.util.List;


public class MoviesAdapter extends BaseExpandableListAdapter {
    private Context ctx;
    private HashMap<String, List<String>> Movies_Category;
    private List<String> Movies_List;

    public MoviesAdapter(Context ctx, HashMap<String, List<String>> Movies_Category, List<String> Movies_List) {
        this.ctx = ctx;
        this.Movies_Category = Movies_Category;
        this.Movies_List = Movies_List;

    }

    @Override
    public Object getChild(int parent, int child) {
        return Movies_Category.get(Movies_List.get(parent)).get(child);
    }

    @Override
    public long getChildId(int parent, int child) {
        return child;
    }

    @Override
    public View getChildView(int parent, int child, boolean lastChild, View convertview, ViewGroup parentview  ) {
        String child_title = (String) getChild(parent,child);
        if (convertview == null)
        {
            LayoutInflater inflator = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertview = inflator.inflate(R.layout.child_layout, parentview,false);

        }
            TextView child_textview = (TextView) convertview.findViewById(R.id.child_txt);
            child_textview.setText(child_title);

        return convertview;
    }

    @Override
    public int getChildrenCount(int arg0) {

        return Movies_Category.get(Movies_List.get(arg0)).size();

    }

    @Override
    public Object getGroup(int arg0) {
        return Movies_List.get(arg0);
    }

    @Override
    public int getGroupCount() {

        return Movies_List.size();
    }

    @Override
    public long getGroupId(int arg0) {
        return arg0;
    }

    @Override
    public View getGroupView(int parent, boolean isExpanded, View convertview, ViewGroup parentview){

        String group_title = (String) getGroup(parent);
        if(convertview == null)
        {
            LayoutInflater inflator = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertview = inflator.inflate(R.layout.parent_layout, parentview,false);
        }
        TextView parent_textview = (TextView) convertview.findViewById(R.id.parent_txt);
        parent_textview.setTypeface(null, Typeface.BOLD);
        parent_textview.setText(group_title);

    return convertview;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public boolean isChildSelectable(int arg0, int arg1) {
        return true;
    }

}
  

DataProvider.java

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by User on 2/3/2016.
 */
public class DataProvider {
    public static HashMap<String, List<String>> getInfo() {
        HashMap<String, List<String>> MoviesDetails = new HashMap<String, List<String>>();
        List<String> Beginner_Movies = new ArrayList<String>();
        Beginner_Movies.add("Hello");
        Beginner_Movies.add("How Are you?");
        Beginner_Movies.add("What Are you doing?");
        Beginner_Movies.add("Where are you going?");
        Beginner_Movies.add("Can i come?");
        Beginner_Movies.add("Goodbye");
        List<String> Medium_Movies = new ArrayList<String>();
        Medium_Movies.add("Can i come?");
        Medium_Movies.add("Whats your name?");
        Medium_Movies.add("Where are you from?");
        List<String> Expert_Movies = new ArrayList<String>();
        Expert_Movies.add("Can you teach me how to..");
        Expert_Movies.add("Where is the best place to go?");
        Expert_Movies.add("I hope to see you again");

        MoviesDetails.put("Beginner", Beginner_Movies);
        MoviesDetails.put("Intermediate", Medium_Movies);
        MoviesDetails.put("Expert", Expert_Movies);

        return MoviesDetails;
    }
}

0 个答案:

没有答案