date = (DatePicker)findViewById(R.id.date);
diary = (EditText)findViewById(R.id.diary);
btn = (Button)findViewById(R.id.btn);
Calendar cal = Calendar.getInstance();
cYear = cal.get(Calendar.YEAR);
cMonth = cal.get(Calendar.MONTH);
cDay = cal.get(Calendar.DAY_OF_MONTH);
date.init(cYear, cMonth, cDay, new DatePicker.OnDateChangedListener() {
public void onDateChanged(DatePicker v, int y, int m, int d) {
fname = Integer.toString(y) + "-" +
Integer.toString(m+1) + "-" +
Integer.toString(d) + ".txt";
String str = readDiary(fname);
diary.setText(str);
btn.setEnabled(true);
}
});
btn.setOnClickListener(new View.OnClickListener() {
@SuppressLint("NewApi")
public void onClick(View arg0) {
FileOutputStream outFs;
try {
outFs = openFileOutput(fname, Context.MODE_ENABLE_WRITE_AHEAD_LOGGING);
String str = diary.getText().toString();
outFs.write(str.getBytes());
outFs.close();
Toast.makeText(getApplicationContext(), fname+"이 저장됨", Toast.LENGTH_LONG).show();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
private String readDiary(String fname) {
String diarystr = null;
FileInputStream inFs;
try {
inFs = openFileInput(fname);
byte[] txt = new byte[500];
inFs.read(txt);
inFs.close();
diarystr = (new String(txt)).trim();
btn.setText("수정하기");
} catch (IOException e) {
diary.setHint("일기없음");
btn.setText("저장");
}
return diarystr;
}
}
안녕하세요 안드로이드를 배우는 학생입니다. 다른 액티비티는 사진갤러리와 카메라를 연동해서 이미지를 가져오는것으로 했습니다.이 가져온 이미지를 지금 액티비티에서 달력의 날짜가 바뀔때마다 글과 사진을 올릴수있는 다이어리를 만들고 싶은데 그럼 이미지저장을 어떻게 해야하는지 모르겠습니다. 도와주세요!