0

(DatePickerActivity) >> to select type of note (SelectTypeActivity) >> to write the txt file (WriteNoteActivity). This is the process. But I have to change the intent SelectTypeActivity.class to WriteNoteActivity.class like this it will success, how can I no need to skip the SelectTypeActivity also able to do that ? =)

DatePickerActivity = create folder

 public void onClick(DialogInterface dialog, int which) { 

                          Environment.getExternalStorageDirectory();
                             String dateN = edit_date.getText().toString();


                             edit_date.setTypeface(edit_date.getTypeface(), Typeface.BOLD_ITALIC);
                                File folder = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/CalendarNote/" + dateN);
                                boolean success = true;
                                    if (!folder.exists()) {
                                        success = folder.mkdirs();


                                    }
                                    if (success) {
                                            Toast.makeText(getBaseContext(), "You have successfully created." , Toast.LENGTH_LONG ).show();
                                            Intent w = new Intent(DatePickerActivity.this, WriteNoteActivity.class);
                                            w.putExtra("the_date", dateN);
                                            startActivity(w);


                                    } else {
                                        Toast.makeText(getBaseContext(), "You have Failed to create." , Toast.LENGTH_LONG ).show();
                                    }

                        }
                     })

WriteNoteActivity = create txt file

        public void onClick(DialogInterface dialog, int which) { 
             String content = edit_content.getText().toString();
             String title = edit_title.getText().toString();
             //String dateN = edit_date.getText().toString();


             boolean success = true;
                 try {
                    String dateN = getIntent().getStringExtra("the_date");
                    File sdCardDir = Environment.getExternalStorageDirectory();  
                    File targetFile;

                    targetFile = new File(sdCardDir.getCanonicalPath()  
                            + "/CalendarNote/" + dateN );


                    // File file=new File(folderPath + "/"+title+".txt");
                    File file=new File(targetFile + "/"+title+".txt");

                    if(!targetFile.exists()){
                        success = targetFile.mkdir();  
                    }
                    RandomAccessFile raf = new RandomAccessFile(file, "rw");  
                    raf.seek(file.length());  

                    raf.write(content.getBytes());  
                    raf.close();  
                } catch (IOException e) {
                    e.printStackTrace();
                } 
                 if (success) {
                    Toast.makeText(getBaseContext(), "You have successfully created." , Toast.LENGTH_LONG ).show();



            } else {
                Toast.makeText(getBaseContext(), "You have Failed to create." , Toast.LENGTH_LONG ).show();
            }
                    //Toast.makeText(getBaseContext(), "Note have successfully saved." , Toast.LENGTH_LONG ).show();
                }
             })

Any suggestion to not skip the SelectTypeActivity ? also able to getStringExtra from DatePickerActivity

Frozen
  • 97
  • 1
  • 4
  • 15
  • What is the problem with displaying select type activity? – Tech Agent Mar 15 '14 at 12:16
  • @TechAgent SelectTypeActivity no problem. Because I want to getStringExtra **(WriteNoteActivity)** have to intent the putExtra **(DatePickerActivity)** to the correct Activity which is `Intent w = new Intent(DatePickerActivity.this, WriteNoteActivity.class);` but the process is to pass to **SelectTypeActivity** . In **SelectTypeActivity** I choose the type of note [txt note] then only move to the WriteNoteActivity. How to not skip the **SelectTypeActivity** also able to passing the **putExtra** to the **getStringExtra** . – Frozen Mar 15 '14 at 12:33

1 Answers1

0

i will going changing SelectTypeActivity into a dialog, if the only purpose of this activity is showing the different type of notes you can do a dialog over a dialog programatically like this (instead of going to SelectTypeActivity activity):

Dialog dialog = new Dialog(this);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Select Color Mode");

ListView modeList = new ListView(this);
String[] stringArray = new String[] { "Bright Mode", "Normal Mode" };
ArrayAdapter<String> modeAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, stringArray);
modeList.setAdapter(modeAdapter);

builder.setView(modeList);
dialog = builder.create();

Then handling the onclick button with .setPositiveButton

Check here for more details: How to click 'OK' on an AlertDialog via code?

Obviusly you have to populate the modeList with your type of notes

Hope i helped you :)

Community
  • 1
  • 1
MatPag
  • 41,742
  • 14
  • 105
  • 114
  • Hi, I have think this solution before. But the SelectTypeActivity have their own Interface with cool layout. However is this the only way to change the layout to dialog? =( – Frozen Mar 15 '14 at 12:41
  • if you want use a custom XML layout you can follow this guide http://www.mkyong.com/android/android-custom-dialog-example/ or this guide http://stackoverflow.com/questions/13341560/how-to-create-a-custom-dialog-box-in-android if this helped you pls mark the answer as the accepted one, thanks :) – MatPag Mar 15 '14 at 14:11