달력

4

« 2024/4 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
2011. 8. 30. 15:26

EditText 에 입력하여 file로 저장하기 Study/Android2011. 8. 30. 15:26

public class MyFile extends Activity implements OnClickListener {
/** Called when the activity is first created. */
//사용할 것들
EditText edit;
Button btn;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//findViewById를 이용해 id 값을 불러옴
edit = (EditText) findViewById(R.id.editText);
btn = (Button) findViewById(R.id.button);

//button을 클릭하면 이벤트 발생
btn.setOnClickListener(this);
}

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

//id 값을 가져와서 R.id.button 값일 경우 실행
switch(v.getId()){
case R.id.button:
try {

//입력받은 값을 String 형으로 저장함
String txt = edit.getText().toString();

//test.txt 파일을 쓰기 권한으로 줌
FileOutputStream outstream = openFileOutput("test.txt",
Activity.MODE_WORLD_WRITEABLE);
//byte 단위로 입력함
outstream.write(txt.getBytes());

//Exception이 발생하지 않았으므로 저장완료 Toast를 띄움
Toast.makeText(this, "저장완료!!", Toast.LENGTH_LONG).show();

} catch (Exception e) {

e.printStackTrace();
//Exception이 발생하였으므로 저장실패 Toast를 띄움
Toast.makeText(this, "저장실패!", Toast.LENGTH_LONG).show();
}
}

}
}

'Study > Android' 카테고리의 다른 글

지도기능 이용하기  (0) 2011.09.01
file저장기법+OptionMenu+dialog 어차피 OptionMenu부분만 추가되었음..  (0) 2011.08.31
File저장기법+dialog를 이용해 보기  (0) 2011.08.31
Data Storage 中 Preferences  (0) 2011.08.30
TextView 그림자처리와 자동링크  (0) 2011.08.30
px (vs) dp  (0) 2011.08.29
상태바 Notification 예제 파일분석  (0) 2011.08.29
Intent  (0) 2011.08.29
getSystemService  (0) 2011.08.29
Style / Theme  (0) 2011.08.29
:
Posted by 유쾌한순례자
2011. 8. 30. 13:57

Data Storage 中 Preferences Study/Android2011. 8. 30. 13:57

화면저장방식. 게임같은곳에서 셋팅같은것등 ( 말그대로 화면을 저장한다고 생각하면 되겠다.)
 
activity 라이프사이클에서 판단해서 사용하면 되는데 대부분 onStop에서 저장을

onStart에서 불러오는것이 보편적인 방법이다.

        //현재화면상태정보를 pref  라는 key이름으로 가져옴
        SharedPreferences pref = getSharedPreferences("pref", Activity.MODE_PRIVATE); 
  
 
       //findViewById로 각 id 값을 가져옴
        EditText edit1 = (EditText)findViewById(R.id.EditText);
CheckBox check1 = (CheckBox)findViewById(R.id.CheckBox01);
CheckBox check2 = (CheckBox)findViewById(R.id.CheckBox02);
 
        //pref에 저장되어 있는  값을 가져오는데 "이름" ,"만약 값이 없을경우 Default 값" 형태로 사용한다. 
String text = pref.getString("editText", "");
Boolean chk1 = pref.getBoolean("check1", false);
Boolean chk2 = pref.getBoolean("check2", false);
 
        //값을 set 함 
edit1.setText(text);
check1.setChecked(chk1);
check2.setChecked(chk2); 






//activity life cycle   ... onStop()

        //현재화면저장정보를 pref 란 key 값으로 가져옴
SharedPreferences pref = getSharedPreferences("pref", Activity.MODE_PRIVATE);
              
 
       //Editor 클래스를 이용해 저장할거임
        SharedPreferences.Editor editor = pref.edit(); 
 
EditText edit1 = (EditText)findViewById(R.id.EditText);
CheckBox check1 = (CheckBox)findViewById(R.id.CheckBox01);
CheckBox check2 = (CheckBox)findViewById(R.id.CheckBox02);
 
// 저장할 값들을 입력
editor.putString("editText", edit1.getText().toString());
editor.putBoolean("check1", check1.isChecked());
editor.putBoolean("check2", check2.isChecked()); 

'Study > Android' 카테고리의 다른 글

지도기능 이용하기  (0) 2011.09.01
file저장기법+OptionMenu+dialog 어차피 OptionMenu부분만 추가되었음..  (0) 2011.08.31
File저장기법+dialog를 이용해 보기  (0) 2011.08.31
EditText 에 입력하여 file로 저장하기  (0) 2011.08.30
TextView 그림자처리와 자동링크  (0) 2011.08.30
px (vs) dp  (0) 2011.08.29
상태바 Notification 예제 파일분석  (0) 2011.08.29
Intent  (0) 2011.08.29
getSystemService  (0) 2011.08.29
Style / Theme  (0) 2011.08.29
:
Posted by 유쾌한순례자
2011. 8. 30. 11:51

TextView 그림자처리와 자동링크 Study/Android2011. 8. 30. 11:51

TextView 속성중

shadowColor, shadowRadius(그림자범위) 

autoLink(자동링크) 

'Study > Android' 카테고리의 다른 글

지도기능 이용하기  (0) 2011.09.01
file저장기법+OptionMenu+dialog 어차피 OptionMenu부분만 추가되었음..  (0) 2011.08.31
File저장기법+dialog를 이용해 보기  (0) 2011.08.31
EditText 에 입력하여 file로 저장하기  (0) 2011.08.30
Data Storage 中 Preferences  (0) 2011.08.30
px (vs) dp  (0) 2011.08.29
상태바 Notification 예제 파일분석  (0) 2011.08.29
Intent  (0) 2011.08.29
getSystemService  (0) 2011.08.29
Style / Theme  (0) 2011.08.29
:
Posted by 유쾌한순례자