Java 在自定义列表视图中单击按钮时获得正确的声音

Java 在自定义列表视图中单击按钮时获得正确的声音,java,android,Java,Android,我有listview和textview和imagebutton,单击按钮时声音会正确播放,但在应用搜索列表项时,我单击了按钮,按钮会产生错误的声音。这些声音被放在原始文件夹中 MainActivity.java public class MainActivity extends Activity { ListViewAdapter adapter; ArrayList<DictionaryApp> arrayList = new ArrayList(); String[] cuyun

我有listview和textview和imagebutton,单击按钮时声音会正确播放,但在应用搜索列表项时,我单击了按钮,按钮会产生错误的声音。这些声音被放在原始文件夹中

MainActivity.java
public class MainActivity extends Activity {
ListViewAdapter adapter;
ArrayList<DictionaryApp> arrayList = new ArrayList();
String[] cuyuno;
String[] edefinition;
EditText editsearch;
String[] english;
ListView list;
String[] tagalog;
String[] tbaybay;
String[] tdefinition;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    this.tagalog = new String[]{"alaala", "araw", "baliw", "basura", "kahirapan", "kaibigan", "kakatuwa", "kasunduan", "daluyang-luha", "dambuhala", "dulo", "dukutin", "gawin", "guni-guni", "hagdan", "hintay", "idlip", "idolo", "maganda", "masama", "masarap", "matalino", "nagtanan", "nawala", "pagbibitiw", "paikliin"};
    this.tbaybay = getResources().getStringArray(R.array.tbaybay);
    this.tdefinition = getResources().getStringArray(R.array.tdefinition);
    this.cuyuno = getResources().getStringArray(R.array.cuyuno);
    this.english = getResources().getStringArray(R.array.eword);
    this.edefinition = getResources().getStringArray(R.array.edefinition);
    this.list = (ListView) findViewById(R.id.listview);
    for (int i = 0; i < this.tagalog.length; i++) {
        this.arrayList.add(new DictionaryApp(this.tagalog[i], this.tbaybay[i], this.tdefinition[i], this.cuyuno[i], this.english[i], this.edefinition[i]));
    }
    this.adapter = new ListViewAdapter(this, this.arrayList);
    this.list.setAdapter(this.adapter);
    this.editsearch = (EditText) findViewById(R.id.search);
    this.editsearch.addTextChangedListener(new TextWatcher() {
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
        }

        public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
        }

        public void afterTextChanged(Editable arg0) {
            MainActivity.this.adapter.filter(MainActivity.this.editsearch.getText().toString().toLowerCase(Locale.getDefault()));
        }
    });
}
}
ListViewAdapter.java

public class ListViewAdapter extends BaseAdapter {
private ArrayList<DictionaryApp> arraylist;
private List<DictionaryApp> dictionaryapplist = null;
LayoutInflater inflater;
Context mContext;
MediaPlayer mp;

public class ViewHolder {
    TextView cuyuno;
    TextView edefinition;
    TextView english;
    ImageButton sound;
    TextView tagalog;
    TextView tbaybay;
    TextView tdefinition;
}

public ListViewAdapter(Context context, List<DictionaryApp> dictionaryapplist) {
    this.mContext = context;
    this.dictionaryapplist = dictionaryapplist;
    this.inflater = LayoutInflater.from(this.mContext);
    this.arraylist = new ArrayList();
    this.arraylist.addAll(dictionaryapplist);
 }

public int getCount() {
    return this.dictionaryapplist.size();
}

public DictionaryApp getItem(int position) {
    return (DictionaryApp) this.dictionaryapplist.get(position);
}

public long getItemId(int position) {
    return (long) position;
}

public View getView(final int position, View view, ViewGroup parent) {
    ViewHolder holder;
    if (view == null) {
        holder = new ViewHolder();
        view = this.inflater.inflate(R.layout.listview_item, null);
        holder.tagalog = (TextView) view.findViewById(R.id.tagalog);
        holder.tbaybay = (TextView) view.findViewById(R.id.tbaybay);
        holder.tdefinition = (TextView) view.findViewById(R.id.tdefinition);
        holder.cuyuno = (TextView) view.findViewById(R.id.cuyuno);
        holder.english = (TextView) view.findViewById(R.id.english);
        holder.edefinition = (TextView) view.findViewById(R.id.edefinition);
        holder.sound = (ImageButton) view.findViewById(R.id.sound);
        view.setTag(holder);
    } else {
        holder = (ViewHolder) view.getTag();
    }
    holder.tagalog.setText(((DictionaryApp) this.dictionaryapplist.get(position)).getTagalog());
    holder.tbaybay.setText(((DictionaryApp) this.dictionaryapplist.get(position)).getTbaybay());
    holder.tdefinition.setText(((DictionaryApp) this.dictionaryapplist.get(position)).getTdefinition());
    holder.cuyuno.setText(((DictionaryApp) this.dictionaryapplist.get(position)).getCuyuno());
    holder.english.setText(((DictionaryApp) this.dictionaryapplist.get(position)).getEnglish());
    holder.edefinition.setText(((DictionaryApp) this.dictionaryapplist.get(position)).getEdefinition());
    holder.sound.setTag(Integer.valueOf(position));
    holder.sound.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            switch ((int) ListViewAdapter.this.getItemId(position)) {
                case R.styleable.View_android_theme /*0*/:
                    ListViewAdapter.this.mp = MediaPlayer.create(ListViewAdapter.this.mContext, R.raw.alaala);
                    ListViewAdapter.this.mp.start();
                    return;
                case R.styleable.View_android_focusable /*1*/:
                    ListViewAdapter.this.mp = MediaPlayer.create(ListViewAdapter.this.mContext, R.raw.araw);
                    ListViewAdapter.this.mp.start();
                    return;
                case R.styleable.View_paddingEnd /*3*/:
                    ListViewAdapter.this.mp = MediaPlayer.create(ListViewAdapter.this.mContext, R.raw.baliw);
                    ListViewAdapter.this.mp.start();
                    return;
                case R.styleable.View_theme /*4*/:
                    ListViewAdapter.this.mp = MediaPlayer.create(ListViewAdapter.this.mContext, R.raw.basura);
                    ListViewAdapter.this.mp.start();
                    return;
                case R.styleable.Toolbar_contentInsetStart /*5*/:
                    ListViewAdapter.this.mp = MediaPlayer.create(ListViewAdapter.this.mContext, R.raw.kaibigan);
                    ListViewAdapter.this.mp.start();
                    return;
                case R.styleable.Toolbar_contentInsetEnd /*6*/:
                    ListViewAdapter.this.mp = MediaPlayer.create(ListViewAdapter.this.mContext, R.raw.kakatuwa);
                    ListViewAdapter.this.mp.start();
                    return;
                case R.styleable.Toolbar_contentInsetLeft /*7*/:
                    ListViewAdapter.this.mp = MediaPlayer.create(ListViewAdapter.this.mContext, R.raw.kasunduan);
                    ListViewAdapter.this.mp.start();
                    return;
                default:
                    return;
            }
        }
    });
    view.setOnClickListener(new OnClickListener() {
        public void onClick(View arg0) {
            Intent intent = new Intent(ListViewAdapter.this.mContext, SingleItemView.class);
            intent.putExtra("tagalog", ((DictionaryApp) ListViewAdapter.this.dictionaryapplist.get(position)).getTagalog());
            intent.putExtra("tbaybay", ((DictionaryApp) ListViewAdapter.this.dictionaryapplist.get(position)).getTbaybay());
            intent.putExtra("tdefinition", ((DictionaryApp) ListViewAdapter.this.dictionaryapplist.get(position)).getTdefinition());
            intent.putExtra("cuyuno", ((DictionaryApp) ListViewAdapter.this.dictionaryapplist.get(position)).getCuyuno());
            intent.putExtra("english", ((DictionaryApp) ListViewAdapter.this.dictionaryapplist.get(position)).getEnglish());
            intent.putExtra("edefinition", ((DictionaryApp) ListViewAdapter.this.dictionaryapplist.get(position)).getEdefinition());
            ListViewAdapter.this.mContext.startActivity(intent);
        }
    });
    return view;
}

public void filter(String charText) {
    charText = charText.toLowerCase(Locale.getDefault());
    this.dictionaryapplist.clear();
    if (charText.length() == 0) {
        this.dictionaryapplist.addAll(this.arraylist);
    } else {
        Iterator i$ = this.arraylist.iterator();
        while (i$.hasNext()) {
            DictionaryApp da = (DictionaryApp) i$.next();
            if (da.getTagalog().toLowerCase(Locale.getDefault()).contains(charText)) {
                this.dictionaryapplist.add(da);
            }
        }
    }
    notifyDataSetChanged();
}
}
公共类ListViewAdapter扩展了BaseAdapter{
私有ArrayList ArrayList;
私有列表字典应用程序=null;
充气机;
语境;
MediaPlayer mp;
公共类视图持有者{
TextView cuyuno;
文本视图定义;
文本视图英语;
图像按钮声音;
TextView tagalog;
TextView tbaybay;
文本视图定义;
}
公共ListViewAdapter(上下文、列表字典应用程序){
this.mContext=上下文;
this.dictionaryapplist=dictionaryapplist;
this.inflater=LayoutInflater.from(this.mContext);
this.arraylist=新的arraylist();
this.arraylist.addAll(字典应用程序);
}
public int getCount(){
返回此.dictionaryApplication.size();
}
公共字典yapp getItem(int位置){
return(DictionaryApp)this.dictionaryapplist.get(position);
}
公共长getItemId(int位置){
返回(长)位置;
}
公共视图getView(最终整数位置、视图视图、视图组父视图){
视窗座;
如果(视图==null){
holder=新的ViewHolder();
视图=此.inflater.inflate(R.layout.listview\u项,空);
holder.tagalog=(TextView)view.findViewById(R.id.tagalog);
holder.tbaybay=(TextView)view.findViewById(R.id.tbaybay);
holder.tdefinition=(TextView)view.findViewById(R.id.tdefinition);
holder.cuyuno=(TextView)view.findViewById(R.id.cuyuno);
holder.english=(TextView)view.findViewById(R.id.english);
holder.edefinition=(TextView)view.findViewById(R.id.edefinition);
holder.sound=(ImageButton)view.findViewById(R.id.sound);
视图.设置标签(支架);
}否则{
holder=(ViewHolder)view.getTag();
}
holder.tagalog.setText(((DictionaryApp)this.dictionaryaapplist.get(position)).getTagalog();
holder.tbaybay.setText(((DictionaryApp)this.dictionaryaapplist.get(position)).getTbaybay();
holder.tdefinition.setText(((DictionaryApp)this.dictionaryaapplist.get(position)).getTdefinition();
holder.cuyuno.setText(((DictionaryApp)this.dictionaryaapplist.get(position)).getCuyuno();
holder.english.setText(((DictionaryApp)this.dictionaryaapplist.get(position)).getEnglish();
holder.edefinition.setText(((DictionaryApp)this.dictionaryaapplist.get(position)).getEdefinition();
holder.sound.setTag(整数值(位置));
holder.sound.setOnClickListener(新的OnClickListener(){
公共void onClick(视图v){
开关((int)ListViewAdapter.this.getItemId(位置)){
case R.styleable.View\u android\u主题/*0*/:
ListViewAdapter.this.mp=MediaPlayer.create(ListViewAdapter.this.mContext,R.raw.alaala);
ListViewAdapter.this.mp.start();
返回;
case R.styleable.View\u android\u focusable/*1*/:
ListViewAdapter.this.mp=MediaPlayer.create(ListViewAdapter.this.mContext,R.raw.araw);
ListViewAdapter.this.mp.start();
返回;
案例R.styleable.View\u paddingEnd/*3*/:
ListViewAdapter.this.mp=MediaPlayer.create(ListViewAdapter.this.mContext,R.raw.baliw);
ListViewAdapter.this.mp.start();
返回;
case R.styleable.View_theme/*4*/:
ListViewAdapter.this.mp=MediaPlayer.create(ListViewAdapter.this.mContext,R.raw.basura);
ListViewAdapter.this.mp.start();
返回;
case R.styleable.Toolbar_contentInsertStart/*5*/:
ListViewAdapter.this.mp=MediaPlayer.create(ListViewAdapter.this.mContext,R.raw.kaibigan);
ListViewAdapter.this.mp.start();
返回;
case R.styleable.Toolbar_contentInsetEnd/*6*/:
ListViewAdapter.this.mp=MediaPlayer.create(ListViewAdapter.this.mContext,R.raw.kakatuwa);
ListViewAdapter.this.mp.start();
返回;
case R.styleable.Toolbar_contentInsettleft/*7*/:
ListViewAdapter.this.mp=MediaPlayer.create(ListViewAdapter.this.mContext,R.raw.kasunduan);
ListViewAdapter.this.mp.start();
返回;
违约:
返回;
}
}
});
view.setOnClickListener(新的OnClickListener(){
公共void onClick(视图arg0){
Intent Intent=newintent(ListViewAdapter.this.mContext,SingleItemView.class);
intent.putExtra(“tagalog”,((DictionaryApp)ListViewAdapter.this.dictionaryapplict.get(position)).getTagalog());
intent.putExtra(“tbaybay”,((DictionaryApp)ListViewAdapter.this.dictionaryapplict.get(position)).getTbaybay();
intent.putExtra(“tdefinition”,((DictionaryApp)ListViewAdapter.this.dictionaryapplict.get(position)).getDefinition();
intent.putExtra(“cuyuno”,((DictionaryApp)ListViewAdapter.this.dictionaryapplict.get(position)).getCuyuno();
intent.putExtra(“english”,((DictionaryApp)ListViewAdapter.this.dictionaryaapplist.get(position)).getEnglish();
intent.putExtra(“edefinition”,((DictionaryApp)ListViewAdapter.this.DictionaryApplication.get(position)).getEdefinition();
ListViewAdapter.this.mContext.startActivity(intent);
}
});
返回视图;
}
公共空过滤器(字符串图表文本){
charText=charText.toLowerCase(Locale.getDefault());
this.dictionaryaapplist.clear();
如果(ChartText.length()==0){
this.dictionaryaapplist.addAll(this.arraylist);
}埃尔斯
public class ListViewAdapter extends BaseAdapter {
private ArrayList<DictionaryApp> arraylist;
private List<DictionaryApp> dictionaryapplist = null;
LayoutInflater inflater;
Context mContext;
MediaPlayer mp;

public class ViewHolder {
    TextView cuyuno;
    TextView edefinition;
    TextView english;
    ImageButton sound;
    TextView tagalog;
    TextView tbaybay;
    TextView tdefinition;
}

public ListViewAdapter(Context context, List<DictionaryApp> dictionaryapplist) {
    this.mContext = context;
    this.dictionaryapplist = dictionaryapplist;
    this.inflater = LayoutInflater.from(this.mContext);
    this.arraylist = new ArrayList();
    this.arraylist.addAll(dictionaryapplist);
 }

public int getCount() {
    return this.dictionaryapplist.size();
}

public DictionaryApp getItem(int position) {
    return (DictionaryApp) this.dictionaryapplist.get(position);
}

public long getItemId(int position) {
    return (long) position;
}

public View getView(final int position, View view, ViewGroup parent) {
    ViewHolder holder;
    if (view == null) {
        holder = new ViewHolder();
        view = this.inflater.inflate(R.layout.listview_item, null);
        holder.tagalog = (TextView) view.findViewById(R.id.tagalog);
        holder.tbaybay = (TextView) view.findViewById(R.id.tbaybay);
        holder.tdefinition = (TextView) view.findViewById(R.id.tdefinition);
        holder.cuyuno = (TextView) view.findViewById(R.id.cuyuno);
        holder.english = (TextView) view.findViewById(R.id.english);
        holder.edefinition = (TextView) view.findViewById(R.id.edefinition);
        holder.sound = (ImageButton) view.findViewById(R.id.sound);
        view.setTag(holder);
    } else {
        holder = (ViewHolder) view.getTag();
    }
    holder.tagalog.setText(((DictionaryApp) this.dictionaryapplist.get(position)).getTagalog());
    holder.tbaybay.setText(((DictionaryApp) this.dictionaryapplist.get(position)).getTbaybay());
    holder.tdefinition.setText(((DictionaryApp) this.dictionaryapplist.get(position)).getTdefinition());
    holder.cuyuno.setText(((DictionaryApp) this.dictionaryapplist.get(position)).getCuyuno());
    holder.english.setText(((DictionaryApp) this.dictionaryapplist.get(position)).getEnglish());
    holder.edefinition.setText(((DictionaryApp) this.dictionaryapplist.get(position)).getEdefinition());
    holder.sound.setTag(Integer.valueOf(position));
    holder.sound.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            switch ((int) ListViewAdapter.this.getItemId(position)) {
                case R.styleable.View_android_theme /*0*/:
                    ListViewAdapter.this.mp = MediaPlayer.create(ListViewAdapter.this.mContext, R.raw.alaala);
                    ListViewAdapter.this.mp.start();
                    return;
                case R.styleable.View_android_focusable /*1*/:
                    ListViewAdapter.this.mp = MediaPlayer.create(ListViewAdapter.this.mContext, R.raw.araw);
                    ListViewAdapter.this.mp.start();
                    return;
                case R.styleable.View_paddingEnd /*3*/:
                    ListViewAdapter.this.mp = MediaPlayer.create(ListViewAdapter.this.mContext, R.raw.baliw);
                    ListViewAdapter.this.mp.start();
                    return;
                case R.styleable.View_theme /*4*/:
                    ListViewAdapter.this.mp = MediaPlayer.create(ListViewAdapter.this.mContext, R.raw.basura);
                    ListViewAdapter.this.mp.start();
                    return;
                case R.styleable.Toolbar_contentInsetStart /*5*/:
                    ListViewAdapter.this.mp = MediaPlayer.create(ListViewAdapter.this.mContext, R.raw.kaibigan);
                    ListViewAdapter.this.mp.start();
                    return;
                case R.styleable.Toolbar_contentInsetEnd /*6*/:
                    ListViewAdapter.this.mp = MediaPlayer.create(ListViewAdapter.this.mContext, R.raw.kakatuwa);
                    ListViewAdapter.this.mp.start();
                    return;
                case R.styleable.Toolbar_contentInsetLeft /*7*/:
                    ListViewAdapter.this.mp = MediaPlayer.create(ListViewAdapter.this.mContext, R.raw.kasunduan);
                    ListViewAdapter.this.mp.start();
                    return;
                default:
                    return;
            }
        }
    });
    view.setOnClickListener(new OnClickListener() {
        public void onClick(View arg0) {
            Intent intent = new Intent(ListViewAdapter.this.mContext, SingleItemView.class);
            intent.putExtra("tagalog", ((DictionaryApp) ListViewAdapter.this.dictionaryapplist.get(position)).getTagalog());
            intent.putExtra("tbaybay", ((DictionaryApp) ListViewAdapter.this.dictionaryapplist.get(position)).getTbaybay());
            intent.putExtra("tdefinition", ((DictionaryApp) ListViewAdapter.this.dictionaryapplist.get(position)).getTdefinition());
            intent.putExtra("cuyuno", ((DictionaryApp) ListViewAdapter.this.dictionaryapplist.get(position)).getCuyuno());
            intent.putExtra("english", ((DictionaryApp) ListViewAdapter.this.dictionaryapplist.get(position)).getEnglish());
            intent.putExtra("edefinition", ((DictionaryApp) ListViewAdapter.this.dictionaryapplist.get(position)).getEdefinition());
            ListViewAdapter.this.mContext.startActivity(intent);
        }
    });
    return view;
}

public void filter(String charText) {
    charText = charText.toLowerCase(Locale.getDefault());
    this.dictionaryapplist.clear();
    if (charText.length() == 0) {
        this.dictionaryapplist.addAll(this.arraylist);
    } else {
        Iterator i$ = this.arraylist.iterator();
        while (i$.hasNext()) {
            DictionaryApp da = (DictionaryApp) i$.next();
            if (da.getTagalog().toLowerCase(Locale.getDefault()).contains(charText)) {
                this.dictionaryapplist.add(da);
            }
        }
    }
    notifyDataSetChanged();
}
}
holder.sound.setTag(Integer.valueOf(position));
public class DictionaryApp {

  private int id;

  private String cuyuno;
  private String edefinition;
  private String english;
  private String tagalog;
  private String tbaybay;
  private String tdefinition;
}