【发布时间】:2014-05-27 09:44:37
【问题描述】:
图像中的类似应用程序设置为铃声和通知声音我该怎么做。 原始铃声文件夹。
GridView 中有 20 个单元的鸟鸣声。 鸟图片播放声音按 长按“铃声选择”和“通知声音选择”设置必须显示如何。 http://appcrawlr.com/android/sounds-of-birds-ringtones
MainActivity.java;
public class MainActivity extends Activity implements OnItemClickListener {
MediaPlayer mp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
GridView gridView = (GridView) findViewById(R.id.gridView1);
gridView.setAdapter(new ImageAdapter(this));
registerForContextMenu(gridView);
gridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View gorunum,
int position, long id) {
if (position == 0) {
if (mp != null) {
mp.release();
mp = null;
}
mp = MediaPlayer.create(MainActivity.this,
R.raw.american_crow);
mp.start();
Toast.makeText(MainActivity.this, "American Crow",
Toast.LENGTH_SHORT).show();
}
if (position == 1) {
if (mp != null) {
mp.release();
mp = null;
}
mp = MediaPlayer.create(MainActivity.this,
R.raw.american_goldfinch);
mp.start();
Toast.makeText(MainActivity.this, "American Goldfinch",
Toast.LENGTH_SHORT).show();
}
if (position == 2) {
if (mp != null) {
mp.release();
mp = null;
}
mp = MediaPlayer.create(MainActivity.this,
R.raw.american_kestrel);
mp.start();
Toast.makeText(MainActivity.this, "American Kestrel",
Toast.LENGTH_SHORT).show();
}
if (position == 3) {
if (mp != null) {
mp.release();
mp = null;
}
mp = MediaPlayer.create(MainActivity.this,
R.raw.american_robin);
mp.start();
Toast.makeText(MainActivity.this, "American Robin",
Toast.LENGTH_SHORT).show();
}
if (position == 4) {
if (mp != null) {
mp.release();
mp = null;
}
mp = MediaPlayer.create(MainActivity.this,
R.raw.baltimore_oriole);
mp.start();
Toast.makeText(MainActivity.this, "Baltimore Oriole",
Toast.LENGTH_SHORT).show();
}
if (position == 5) {
if (mp != null) {
mp.release();
mp = null;
}
mp = MediaPlayer.create(MainActivity.this,
R.raw.barn_swallow);
mp.start();
Toast.makeText(MainActivity.this, "Barn Swallow",
Toast.LENGTH_SHORT).show();
}
if (position == 6) {
if (mp != null) {
mp.release();
mp = null;
}
mp = MediaPlayer.create(MainActivity.this,
R.raw.blue_cheeked_bee_eater);
mp.start();
Toast.makeText(MainActivity.this, "Blue Cheeked Bee Eater",
Toast.LENGTH_SHORT).show();
}
if (position == 7) {
if (mp != null) {
mp.release();
mp = null;
}
mp = MediaPlayer.create(MainActivity.this, R.raw.blue_jay);
mp.start();
Toast.makeText(MainActivity.this, "Blue Jay",
Toast.LENGTH_SHORT).show();
}
if (position == 8) {
if (mp != null) {
mp.release();
mp = null;
}
mp = MediaPlayer.create(MainActivity.this,
R.raw.brown_headed_nuthatch);
mp.start();
Toast.makeText(MainActivity.this, "Brown Headed Nuthatch",
Toast.LENGTH_SHORT).show();
}
if (position == 9) {
if (mp != null) {
mp.release();
mp = null;
}
mp = MediaPlayer
.create(MainActivity.this, R.raw.budgerigar);
mp.start();
Toast.makeText(MainActivity.this, "Buggerigar",
Toast.LENGTH_SHORT).show();
}
if (position == 10) {
if (mp != null) {
mp.release();
mp = null;
}
mp = MediaPlayer.create(MainActivity.this, R.raw.canary);
mp.start();
Toast.makeText(MainActivity.this, "Canary",
Toast.LENGTH_SHORT).show();
}
if (position == 11) {
if (mp != null) {
mp.release();
mp = null;
}
mp = MediaPlayer.create(MainActivity.this,
R.raw.carolina_chickadee);
mp.start();
Toast.makeText(MainActivity.this, "Carolina Chickadee",
Toast.LENGTH_SHORT).show();
}
if (position == 12) {
if (mp != null) {
mp.release();
mp = null;
}
mp = MediaPlayer.create(MainActivity.this,
R.raw.carolina_wren);
mp.start();
Toast.makeText(MainActivity.this, "Carolina Wren",
Toast.LENGTH_SHORT).show();
}
if (position == 13) {
if (mp != null) {
mp.release();
mp = null;
}
mp = MediaPlayer.create(MainActivity.this,
R.raw.chestnut_sided_warbler);
mp.start();
Toast.makeText(MainActivity.this,
"Chesthunt Sided Warbler", Toast.LENGTH_SHORT)
.show();
}
if (position == 14) {
if (mp != null) {
mp.release();
mp = null;
}
mp = MediaPlayer.create(MainActivity.this,
R.raw.chimney_swift);
mp.start();
Toast.makeText(MainActivity.this, "Chimney Swift",
Toast.LENGTH_SHORT).show();
}
if (position == 15) {
if (mp != null) {
mp.release();
mp = null;
}
mp = MediaPlayer.create(MainActivity.this,
R.raw.common_grackle);
mp.start();
Toast.makeText(MainActivity.this, "Comon Grackle",
Toast.LENGTH_SHORT).show();
}
if (position == 16) {
if (mp != null) {
mp.release();
mp = null;
}
mp = MediaPlayer.create(MainActivity.this, R.raw.crane);
mp.start();
Toast.makeText(MainActivity.this, "Crane",
Toast.LENGTH_SHORT).show();
}
if (position == 17) {
if (mp != null) {
mp.release();
mp = null;
}
mp = MediaPlayer.create(MainActivity.this, R.raw.cuckoo);
mp.start();
Toast.makeText(MainActivity.this, "Cuckoo",
Toast.LENGTH_SHORT).show();
}
if (position == 18) {
if (mp != null) {
mp.release();
mp = null;
}
mp = MediaPlayer.create(MainActivity.this,
R.raw.dark_eyed_junco);
mp.start();
Toast.makeText(MainActivity.this, "Dark Eyed Junco",
Toast.LENGTH_SHORT).show();
}
if (position == 19) {
if (mp != null) {
mp.release();
mp = null;
}
mp = MediaPlayer.create(MainActivity.this,
R.raw.downy_woodpecker);
mp.start();
Toast.makeText(MainActivity.this, "Downy Woodpecker",
Toast.LENGTH_SHORT).show();
}
if (position == 20) {
if (mp != null) {
mp.release();
mp = null;
}
mp = MediaPlayer.create(MainActivity.this,
R.raw.eastern_bluebird);
mp.start();
Toast.makeText(MainActivity.this, "Eastern Blue Bird",
Toast.LENGTH_SHORT).show();
}
}
});
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
}
}
sd卡,权限如何。我不知道。 等待帮助 谢谢
ImageAdapter.java
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public Integer[] birdPicture = { R.drawable.american_crow,
R.drawable.american_goldfinch, R.drawable.american_kestre,
R.drawable.american_robin, R.drawable.baltimore_oriole,
R.drawable.barn_swallow, R.drawable.blue_cheeked_bee_eater,
R.drawable.blue_jay, R.drawable.brown_headed_nuthatch,
R.drawable.budgerigar, R.drawable.canary,
R.drawable.carolina_chickadee, R.drawable.carolina_wren,
R.drawable.chestnut_sided_warbler, R.drawable.chimney_swift,
R.drawable.common_grackle, R.drawable.crane, R.drawable.cuckoo,
R.drawable.dark_eyed_junco, R.drawable.downy_woodpecker,
R.drawable.eastern_bluebird
};
// Constructor
public ImageAdapter(Context c) {
mContext = c;
}
@Override
public int getCount() {
return birdPicture.length;
}
@Override
public Object getItem(int position) {
return birdPicture[position];
}
@Override
public long getItemId(int position) {
return (position);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(mContext);
Resources r = Resources.getSystem();
int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
90, r.getDisplayMetrics());
;
imageView
.setLayoutParams(new GridView.LayoutParams((int) px, (int) px));
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setImageResource(birdPicture[position]);
return imageView;
}
}
所有代码中的应用
【问题讨论】:
-
请把问题写得更准确,可以理解..
标签: android gridview notifications ringtone