Java 使用新录音机更新我的列表视图

Java 使用新录音机更新我的列表视图,java,android,listview,Java,Android,Listview,我用一个列表视图来显示我的录音,但是当我录制一个新的时 我想刷新列表视图。 但它不起作用。 我还没有在安卓工作室工作的经验,如果我不在,很抱歉 具体的 你能帮我吗 public class MainActivity extends AppCompatActivity { private Button mRecordBtn; private Button mAtualizarBtn; private TextView mRecordLabe

我用一个列表视图来显示我的录音,但是当我录制一个新的时 我想刷新列表视图。 但它不起作用。 我还没有在安卓工作室工作的经验,如果我不在,很抱歉 具体的 你能帮我吗

    public class MainActivity extends AppCompatActivity {

        private Button mRecordBtn;
        private Button mAtualizarBtn;
        private TextView mRecordLabel;
        private MediaRecorder mRecorder;
        private String mFileName = null;
        private static final String LOG_TAG = "Record_log";
        //private StorageReference mStorage;
        private ProgressDialog mProgress;

        ListView lv;
        String[] items;
        FetchSongs fs;
        ArrayList<File> mySongs;
        ProgressDialog dialog;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            setContentView(R.layout.activity_main);
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
            lv = (ListView) findViewById(R.id.listView);
            fs = new FetchSongs();
            dialog = new ProgressDialog(this);
            dialog.setMessage("Please wait, Fetching Songs...");
            dialog.setCancelable(true);
            dialog.show();


            while (fs.getfetchstatus() != true) {
                mySongs = fs.findSongs(Environment.getExternalStorageDirectory());

            }
            if (mySongs != null) {
                dialog.dismiss();
            }

            mySongs = fs.getsonglist();

            items = new String[mySongs.size()];
            for (int i = 0; i < mySongs.size(); i++) {
                items[i] = mySongs.get(i).getName().toString().replace(".3gp", "");


            }


            final ArrayAdapter<String> adp = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, items);
            lv.setAdapter(adp);
            adp.notifyDataSetChanged();
            lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                    Intent intent = new Intent(getApplicationContext(), Player.class);
                    intent.putExtra("pos", i);
                    adp.notifyDataSetChanged();

                    startActivity(intent);
                    finish();

                }
            });

            //recorder
            mAtualizarBtn = (Button) findViewById(R.id.atualizarBtn);
            mRecordLabel = (TextView) findViewById(R.id.recordLabel);
            mRecordBtn = (Button) findViewById(R.id.recordBtn);

            mProgress = new ProgressDialog(this);
            //mFileName = getExternalCacheDir().getAbsolutePath();

            Long tsLong = System.currentTimeMillis()/1000;
            String ts = tsLong.toString();
            mFileName = Environment.getExternalStorageDirectory().getAbsolutePath() + "/recording-"+ts+".mp3";
            adp.notifyDataSetChanged();

            lv.setAdapter(adp);
            adp.notifyDataSetChanged();
            //mFileName += "/record_audio.MP3";

            mRecordBtn.setOnTouchListener(new View.OnTouchListener()
            {
                @Override
                public boolean onTouch(View view, MotionEvent motionEvent)
                {

                    if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {

                        startRecording();
                        mRecordLabel.setText("GRAVANDO");
                        adp.notifyDataSetChanged();


                    } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {


                        stopRecording();
                        mRecordLabel.setText("Feche o app para " +
                                "atualizar a lista");


                        lv.setAdapter(adp);
                        adp.notifyDataSetChanged();



                    }

                    return false;
                }


            });
        }

        private void startRecording()
        {


            Long tsLong = System.currentTimeMillis()/1000;
            String ts = tsLong.toString();


            mRecorder = new MediaRecorder();
            mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
            mRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
            mRecorder.setOutputFile(mFileName);
            mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
            mFileName = Environment.getExternalStorageDirectory().getAbsolutePath() + "/recording-"+ts+".mp3";

            try
            {
                mRecorder.prepare();

            } catch (IOException e)
            {
                Log.e(LOG_TAG, "prepare() failed");
            }

            mRecorder.start();

        }

        private void stopRecording()
        {

            mRecorder.stop();
            mRecorder.release();
            mRecorder = null;

        }
public类MainActivity扩展了AppCompatActivity{
专用按钮mRecordBtn;
专用按钮mAtualizarBtn;
私有文本视图mRecordLabel;
专用媒体记录器;
私有字符串mFileName=null;
私有静态最终字符串日志\u TAG=“记录\u日志”;
//私有存储器;参考存储器;
私人进程;
ListView lv;
字符串[]项;
取回歌曲;
ArrayList mySongs;
进程对话;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(窗口。功能\u无\u标题);
setContentView(R.layout.activity_main);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_全屏,
WindowManager.LayoutParams.FLAG(全屏);
lv=(ListView)findViewById(R.id.ListView);
fs=新歌曲();
dialog=新建ProgressDialog(此);
setMessage(“请稍候,正在获取歌曲…”);
对话框。可设置可取消(true);
dialog.show();
while(fs.getfetchstatus()!=true){
mySongs=fs.findSongs(Environment.getExternalStorageDirectory());
}
if(mySongs!=null){
dialog.dismise();
}
mySongs=fs.getsonglist();
items=新字符串[mySongs.size()];
for(int i=0;i
如果希望在列表视图中刷新新记录,则每次录制音频/视频后都必须运行这些代码。 while(fs.getfetchstatus()!=true){ mySongs=fs.findSongs(Environment.getExternalStorageDirectory())

}
if(mySongs!=null){
dialog.dismise();
}
mySongs=fs.getsonglist();
items=新字符串[mySongs.size()];
for(int i=0;i
因此,复制此代码并将其粘贴到结尾处的private void stopRecording(){}中。。 也许它会起作用

        }
        if (mySongs != null) {
            dialog.dismiss();
        }

        mySongs = fs.getsonglist();

        items = new String[mySongs.size()];
        for (int i = 0; i < mySongs.size(); i++) {
            items[i] = mySongs.get(i).getName().toString().replace(".3gp", "");