我是Android Studio的新手。我有一个应用程序,该应用程序的主要活动会损害菜单和每个菜单项内部是否为对象的listView。每个对象包含2个textView,一个图像和一个音频文件。单击列表中的项目时,将播放特定的音频文件。我想在mainActivity操作栏中插入自动完成搜索视图,以便用户可以在列表中的任何活动中以及找到时搜索项目并单击它,将播放音频文件。这是我的mainActivity.java文件的一个片段
private AdView mAdView;
GridView gridview;
public static String[] osNameList = {
"NUMBERS",
"FAMILY",
"COLORS",
"NOUNS",
"VERBS",
"PHRASES",
"ANIMALS",
"DATES"
};
public static int[] osImages = {
R.drawable.numbers,
R.drawable.family,
R.drawable.colors,
R.drawable.nouns,
R.drawable.verbs,
R.drawable.phrases,
R.drawable.pawprint,
R.drawable.dates
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
gridview = (GridView) findViewById(R.id.grid);
gridview.setAdapter(new adapter(Main2Activity.this, osNameList, osImages));
这是我的网格适配器的一个片段
rowView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (position == 0){
context.startActivity(new Intent(context, NumbersActivity.class));
}
else if (position == 1){
context.startActivity(new Intent(context, FamilyActivity.class));
}
else if (position == 2){
context.startActivity(new Intent(context, ColorsActivity.class));
}
else if (position == 3){
context.startActivity(new Intent(context, NounsActivityFrags.class));
}
else if (position == 4){
context.startActivity(new Intent(context, VerbsActivity.class));
}
else if (position == 5){
context.startActivity(new Intent(context, PhrasesActivityFrags.class));
}
else if (position == 6){
context.startActivity(new Intent(context, Animals.class));
}
else if (position == 7){
context.startActivity(new Intent(context, CalendarActivityFrags.class));
}
}
});
这是我的一项活动的摘要,其中包含listView中的对象
final ArrayList<Word> word = new ArrayList<Word>();
word.add(new Word("one","kunye",R.drawable.one,R.raw.one));
word.add(new Word("two","kubili",R.drawable.two,R.raw.two));
word.add(new Word("three","kuthathu",R.drawable.three,R.raw.three));
word.add(new Word("four","kune",R.drawable.four,R.raw.four));
word.add(new Word("five","kuhlanu",R.drawable.five,R.raw.five));
word.add(new Word("six","sithandathu",R.drawable.six,R.raw.six));
word.add(new Word("seven","likhomba",R.drawable.seven,R.raw.seven));
word.add(new Word("eight","bunane",R.drawable.eight,R.raw.eight));
word.add(new Word("nine","lithoba",R.drawable.nine,R.raw.nine));
word.add(new Word("ten","itjhumi",R.drawable.ten,R.raw.ten));
word.add(new Word("COUNT ONE TO TEN","",R.raw.onetoten));
WordAdapter adapter = new WordAdapter(this, word, R.color.category_numbers);
ListView listView = (ListView) findViewById(R.id.list);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Word sound = word.get(position);
//Release the media player if it currently exists because we are about to play a different audio file
releaseMediaPlayer();
// Request audio focus for playback
int result = mAudioManager.requestAudioFocus(afChangeListener,
// Use the music stream.
AudioManager.STREAM_MUSIC,
// Request permanent focus.
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
// we have audio focus now
mMediaPlayer = MediaPlayer.create(NumbersActivity.this, sound.getmAudioResourceId());
mMediaPlayer.start();
Toast.makeText(NumbersActivity.this, "Now Playing...", Toast.LENGTH_SHORT).show();
mMediaPlayer.setOnCompletionListener(mOnCompletionListener);
}
}
});
}
我希望用户能够使用英语单词进行搜索,但能够找到整个对象