我正在(缓慢)制作一个应用程序,显示音调列表,并让用户“长按”某个特定的一个,然后调出一个上下文菜单,询问您是否要将其复制到SD卡。 唯一的问题是最后一部分,我需要帮助。基本上音调存储在Raw文件夹中,我需要它将选定的音调文件复制到SD卡,最好是在通知文件夹中。上下文菜单选择后,从原始文件夹复制文件到SD卡?
只是想知道是否有人能给我一个例子,说明我会如何去做这件事,因为我绝对失去了?
这里是我的代码
import java.util.ArrayList;
import android.app.ListActivity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.ListView;
import android.widget.Toast;
public class MainActivity extends ListActivity {
private ArrayList<Sound> mSounds = null;
private SoundAdapter mAdapter = null;
static MediaPlayer mMediaPlayer = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
registerForContextMenu(getListView());
this.getListView().setSelector(R.drawable.selector);
//create a simple list
mSounds = new ArrayList<Sound>();
Sound s = new Sound();
s.setDescription("Anjels");
s.setSoundResourceId(R.raw.anjels);
mSounds.add(s);
s = new Sound();
s.setDescription("Fizz");
s.setSoundResourceId(R.raw.fizz);
mSounds.add(s);
s = new Sound();
s.setDescription("Flipper");
s.setSoundResourceId(R.raw.flipper);
mSounds.add(s);
s = new Sound();
s.setDescription("Glass Key");
s.setSoundResourceId(R.raw.glasskey);
mSounds.add(s);
s = new Sound();
s.setDescription("Halo");
s.setSoundResourceId(R.raw.halo);
mSounds.add(s);
mAdapter = new SoundAdapter(this, R.layout.list_row, mSounds);
setListAdapter(mAdapter);
}
@Override
public void onListItemClick(ListView parent, View v, int position, long id){
Sound s = (Sound) mSounds.get(position);
MediaPlayer mp = MediaPlayer.create(this, s.getSoundResourceId());
mp.start();
}@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context_menu, menu);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
int length = mSounds.size(); // get the length of mSounds object
String[] names = new String[length]; // creates a fixed array with strings
for(int i = 0; i < length; i++) {
// add sound name to string array
names[i] = mSounds.get(i).getDescription(); // returns the string name
}
switch(item.getItemId()) {
case R.id.copytosd:
Toast.makeText(this, "Applying " + getResources().getString(R.string.copy) +
" for " + names[(int)info.id],
Toast.LENGTH_SHORT).show();
return true;
default:
return super.onContextItemSelected(item);
}
}}
我的方式在我头上我这里:-( –
你必须开始somewhe重新...两个月前,我对Java语言一无所知,Android脱离了这个世界......我只是问了一些问题并进行了研究,调查和研究,现在我可以找到解决方法,了解大部分Java和充分了解Android的结构。每天几个小时绰绰有余。试试这个: 1.你试图达到什么目的?例如...将存储在应用程序中的文件写入SD卡。 2.您是否使用过Google?尝试“Android将原始文件写入SD卡教程”或“Android将原始文件写入SD卡的stackoverflow” 3.做教程他们最好 – 2013-08-26 11:43:03
我想这只是我做了一切错误的方式,像我的数组列表哪我知道不应该在主线程中,但它是我可以在网上找到的唯一教程,很容易理解。不幸的是,我住在苏格兰一个非常偏远的地方,想找人帮忙几乎是不可能的。 –