gpt4 book ai didi

java - 单击时如何播放Listview项目的特定声音

转载 作者:行者123 更新时间:2023-12-03 01:56:10 25 4
gpt4 key购买 nike

我创建与声音的Android词典应用程序...我有listview,当选择了一个项目,一个新的 Activity 开,里面的新 Activity 包含4 textviews和图像按钮时,textviews功能完美,但图像按钮没有。音频文件放置在原始文件夹中。如何放置被单击的项目的特定声音?
这是代码:

MainActivityJava

public class MainActivity extends AppCompatActivity {

ListView lv;
SearchView sv;


String[] tagalog= new String[] {"alaala (png.)","araw (png.)","baliw (png.)","basura (png.)",
"kaibigan (png.)","kakatuwa (pu.)", "kasunduan (png.)","dambuhala (png.)",
"dulo (png.)","gawin (pd.)","guni-guni (png.)","hagdan (png.)","hintay (pd.)",
"idlip (png.)","maganda (pu.)","masarap (pu.)", "matalino (pu.)"};

int[] sounds= new int[]{R.raw.alaala,
R.raw.araw,
R.raw.baliw,
R.raw.basura,
R.raw.kaibigan,
R.raw.kakatuwa,
R.raw.kasunduan,
};


ArrayAdapter<String> adapter;

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


lv = (ListView) findViewById(R.id.listView1);
sv = (SearchView) findViewById(R.id.searchView1);

adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,tagalog);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String tagword =tagalog[position];

String[] definition = getResources().getStringArray(R.array.definition);
final String definitionlabel = definition[position];

String[] cuyuno = getResources().getStringArray(R.array.cuyuno);
final String cuyunodefinition = cuyuno[position];

String[] english = getResources().getStringArray(R.array.english);
final String englishdefinition = english[position];


Intent intent = new Intent(getApplicationContext(), DefinitionActivity.class);
intent.putExtra("tagword", tagword);
intent.putExtra("definitionlabel", definitionlabel);
intent.putExtra("cuyunodefinition",cuyunodefinition);
intent.putExtra("englishdefinition", englishdefinition);



startActivity(intent);

}
});


sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String text) {
return false;
}

@Override
public boolean onQueryTextChange(String text) {

adapter.getFilter().filter(text);
return false;
}



});

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
return super.onCreateOptionsMenu(menu);
}

}

DefinitionActivity.java
public class DefinitionActivity extends AppCompatActivity {

MediaPlayer mp;

String tagalogword;
String worddefinition;
String cuyunoword;
String englishword;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_definition);

TextView wordtv = (TextView) findViewById(R.id.wordtv);
TextView definitiontv = (TextView) findViewById(R.id.definitiontv);
TextView cuyunotv = (TextView) findViewById(R.id.cuyunotv);
TextView englishtv = (TextView) findViewById(R.id.englishtv);
ImageButton playbtn = (ImageButton) findViewById(R.id.playbtn);


final Bundle extras = getIntent().getExtras();

if (extras != null) {

tagalogword = extras.getString("tagword");
wordtv.setText(tagalogword);

worddefinition = extras.getString("definitionlabel");
definitiontv.setText(worddefinition);

cuyunoword = extras.getString("cuyunodefinition");
cuyunotv.setText(cuyunoword);

englishword = extras.getString("englishdefinition");
englishtv.setText(englishword);

}

playbtn.setOnClickListener(new View.OnClickListener() {


@Override
public void onClick(View v) {

}
});


}

最佳答案

您可以在意向附加中传递原始id并在meadiaPlayer上播放

关于java - 单击时如何播放Listview项目的特定声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35412750/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com