안드로이드 개발 질문/답변
(글 수 45,052)
public class LunarGugul extends Activity {
DBHandler dbHandler ;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView hello = (TextView)findViewById(R.id.hello) ; // TextView 글자 넣기
long time = System.currentTimeMillis();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy년 MM월 dd일(E)");
Date dd = new Date(time);
try {
hello.append(sdf.format(dd) + " [" + LunarTranser.solarTranse(parse2Date()) + "]") ;
} catch (Exception e) {
hello.append(sdf.format(dd)) ;
}
ListView list = (ListView)findViewById(R.id.ListView) ;
dbHandler = DBHandler.open(this) ;
Cursor cursor = null ;
cursor = dbHandler.selectAll() ;
String[] arr = new String[cursor.getCount()] ;
int count = 0 ;
while (cursor.moveToNext()) {
int _id = cursor.getInt(0) ;
String subject = cursor.getString(1) ;
arr[count] = _id + " " + subject ;
count++ ;
}
cursor.close() ;
dbHandler.close() ;
ArrayAdapter<String> Adapter ;
Adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, arr) ;
list.setAdapter(Adapter) ;
}
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuItem item = menu.add(0, 1, 0, "추가").setIcon(R.drawable.add_item32) ;
item.setAlphabeticShortcut('a') ;
menu.add(0, 2, 0, "삭제").setIcon(R.drawable.delete_item32) ;
menu.add(0, 3, 0, "확인").setIcon(R.drawable.accept_item32) ;
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case 1:
Intent intent = new Intent(this, EntryData.class) ;
startActivity(intent) ;
return true ;
case 2:
Toast.makeText(this, "2번 메뉴", Toast.LENGTH_SHORT).show() ;
return true ;
case 3:
Toast.makeText(this, "3번 메뉴", Toast.LENGTH_SHORT).show() ;
return true ;
}
return false ;
}
public static String parse2Date() {
long time = System.currentTimeMillis();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
Date dd = new Date(time);
return sdf.format(dd);
}
}안녕하세요... 위 소스와 같이 코딩을 하고 있습니다.
이렇게 하면... 프로그램이 시작되면서 listview 가 채워져서 보입니다.
그다음에 추가메뉴를 클릭해서 다른 액티비티 에서 입력을 한개 합니다.
그리고 돌아왔을 때... 처음 화면에 listview 에 새로 추가된 자료가 갱신이 되지 않아서 고민 입니다.
책보면서 하는 코딩이라... 쩝... 알 수 가 없는 일이 생겼습니다.
이런때는 어떻게 할까요 ???
한 수 알려 주세용... 그럼~
2011.01.13 23:25:22
답변은 감사합니다...만... 요기 게시물이나, 인터넷 혹은 책은 보면 저 함수를 호출해 사용하라고 나옵니다. 흑~ 그러나 아직 초짜 인 관계로 다가 저 함수만 보고 어떻게 해야 할찌~... 흑~ 그리고 저 소스의 내용처럼 onCreate 안에서는 저 함수를 써 봐도 나오지 않더군요... 흠... 그래서~ 알고 싶은 것은 입력받는 액티비티에서 저장하고 돌아 나왔을때를 어떻게 알 수 있는 지 그걸 알면 쉬을 텐데... 흑~
2011.01.14 00:19:34
질문자께서 알고 싶은 부분은 혹시 onResume, onPause부분이 아닐까 생각되구요. Activity의 lifecycle에 관한 문서를 찾아보시면 많은 도움이 되리라는 생각이 듭니다.



