Android - 获取上次保存的文件名

时间:2017-04-28 15:39:32

标签: android android-edittext

我有一个List<Course> courses = ofy().load().type(Course.class).filter("course", course).list(); Collections.sort(courses); ,用户可以在其中选择要保存的视频的名称。我想保存该文件/最后一个文件的名称。

已保存文件的目录为EditText

我试过了:

Environment.getExternalStorageDirectory() + "/MyNewApp/MyVidEdits/vidname.mp4"

它只是给了我相同的名字String path= "/MyNewApp/MyVidEdits/1414240995236.mp4"; String filename = path.substring(path.lastIndexOf("/")+1);

EDIT -------

我忘了提到editText在自定义alertDialog中。

编辑2 - 更多细节----并非所有流程都包含在内,只是相关的流程。

1414240995236.mp4

问题是EditText设置为:

//This is where I initialise the EditText
public void onButtonClicked(View view) {
    switch (view.getId()) {
        case R.id.buttonExport:
        AlertDialog.Builder mBuilder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.myDialog));                      
            View mView = LayoutInflater.from(Activity.this).inflate(R.layout.activity_custom_dialog, null);
            final EditText mText = (EditText) mView.findViewById(R.id.edit1);
            mBuilder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    if(!mEmail.getText().toString().isEmpty()){
                    directoryToStore = new File(Environment.getExternalStorageDirectory(),"MyNewApp/MyVidEdits");

        }

// AND HERE IS WHERE I WANT TO CALL THE EDITTEXT

@Override
public void onFinish() {
    String path= "/MyNewApp/MyVidEdits/1.mp4";//it contain your path of image..im using a temp string..
    String filename = path.substring(path.lastIndexOf("/")+1);

    Toast.makeText(getApplicationContext(), filename, Toast.LENGTH_LONG).show();

    File k = new File(Environment.getExternalStorageDirectory() + filename);
                sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(k)));

所以我不能说:

View mView = LayoutInflater.from(Activity.this).inflate(R.layout.activity_custom_dialog, null);
final EditText mText = (EditText) mView.findViewById(R.id.edit1);

1 个答案:

答案 0 :(得分:0)

这是你应该做的:

class myActivity extends Activity {
    String lastSaved = ""; 

    ...

    //This is where I initialise the EditText
    public void onButtonClicked(View view) {
        switch (view.getId()) {
            case R.id.buttonExport:
            AlertDialog.Builder mBuilder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.myDialog));                      
                View mView = LayoutInflater.from(Activity.this).inflate(R.layout.activity_custom_dialog, null);
                final EditText mText = (EditText) mView.findViewById(R.id.edit1);
                mBuilder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        if(!mEmail.getText().toString().isEmpty()){
                        directoryToStore = new File(Environment.getExternalStorageDirectory(),"MyNewApp/MyVidEdits");
                        lastSaved = mText.getText().toString();

            }

    // AND HERE IS WHERE I WANT TO CALL THE EDITTEXT

    @Override
    public void onFinish() {

        Toast.makeText(getApplicationContext(), lastSaved, Toast.LENGTH_LONG).show();

        File k = new File(Environment.getExternalStorageDirectory() + filename);
                    sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(k)));
    }
}