안드로이드 개발 질문/답변
(글 수 45,052)
꼬마네꼬님의 답변을 확인후 수정하여
숫자에 , 는 나오게 끔 수정하였는데 ListView로 뿌려줄떄
따로 TextView를 설정해주지 않아서 그런지
String[] from = new String[] {"JUYUDATE" , "LITER" , "MONEY"};
int[] to = new int[] { R.id.juyu_list_DATE
, R.id.juyu_list_LITER
, R.id.juyu_list_MONEY};
SmsCursorAdapter adapter = new SmsCursorAdapter(this , R.layout.juyu_list, cursor, from, to);
for(int i=0 ; i<adapter.getCursor().getCount() ;i++){
totalValue+=(int)cursor.getInt(4);
cursor.moveToNext();
}
NumberFormat nf = NumberFormat.getInstance();
String strTotalValue = nf.format(totalValue);
total.setText(strTotalValue+"");
System.out.println("totalValue : "+strTotalValue);
setListAdapter(adapter);
public class SmsCursorAdapter extends SimpleCursorAdapter {
public SmsCursorAdapter(Context context
, int layout
, Cursor c
, String[] from
, int[ ] to) {
super(context, layout, c, from, to);
this.setViewBinder(new SmsViewBinder());
}
}
public class SmsViewBinder implements ViewBinder {
private static final String TAG = "SmsViewBinder";
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if(view instanceof TextView) {
int amount = cursor.getInt(4);
NumberFormat nfs = NumberFormat.getInstance();
String strValue = nfs.format(amount);
((TextView)view).setText(strValue);
return true;
}
return false;
}
}
했더니 전부 저렇게 나오네요
날짜 주유량 가격
9,000 9,000L 9,000원
따로따로 TextView 를 설정하는 방법을 잘모르겠습니다
알려주세요~
===원래질문===========================================================================
1. 첫번째 질문입니다 위에서 일단 ListActivity로 뿌려주고 있습니다(LIstView사용)
그리고 그밑에 Total은 따로 TextView로 뿌려주고 있구요
String[] from = new String[] {"JUYUDATE" , "LITER" , "MONEY"};
int[] to = new int[] { R.id.juyu_list_DATE
, R.id.juyu_list_LITER
, R.id.juyu_list_MONEY};
SimpleCursorAdapter juyu_list = new SimpleCursorAdapter(this,
R.layout.juyu_list, cursor, from, to);
//가져온 커서의 내용에서 가격을 전부 가져와 합하여 준다
for(int i=0 ; i<juyu_list.getCursor().getCount() ;i++){
totalValue+=(int)cursor.getInt(4);
cursor.moveToNext();
}
//가격의 총합을 넘버포멧으로 변경하여 세자리마다 ' , '를 찍어준다
NumberFormat nf = NumberFormat.getInstance();
String strTotalValue = nf.format(totalValue);
//출력한다(Total)
total.setText(strTotalValue+"");
//커서로 불러온 리스트를 출력한다
setListAdapter(juyu_list);//여기서 뿌려준것은 가격이 Integer로 DB에 들어가 있습니다
머 이런식인데
Total처럼
위에서 리스트로 뿌려주는것을
9000 => 9,000 이런식으로 뿌여주고 싶은데
어떻게 커서로 불러온것을 수정해야할지모르겠네요
저방식으로는 수정이 불가능한지요??
아니면 DB에서 불러와서 뿌려주는 방식이 저방식말고
다른것으로 해야하는지요 또 그것은 어떤것이 있는지 알고 싶습니다
숫자에 , 는 나오게 끔 수정하였는데 ListView로 뿌려줄떄
따로 TextView를 설정해주지 않아서 그런지
String[] from = new String[] {"JUYUDATE" , "LITER" , "MONEY"};
int[] to = new int[] { R.id.juyu_list_DATE
, R.id.juyu_list_LITER
, R.id.juyu_list_MONEY};
SmsCursorAdapter adapter = new SmsCursorAdapter(this , R.layout.juyu_list, cursor, from, to);
for(int i=0 ; i<adapter.getCursor().getCount() ;i++){
totalValue+=(int)cursor.getInt(4);
cursor.moveToNext();
}
NumberFormat nf = NumberFormat.getInstance();
String strTotalValue = nf.format(totalValue);
total.setText(strTotalValue+"");
System.out.println("totalValue : "+strTotalValue);
setListAdapter(adapter);
public class SmsCursorAdapter extends SimpleCursorAdapter {
public SmsCursorAdapter(Context context
, int layout
, Cursor c
, String[] from
, int[ ] to) {
super(context, layout, c, from, to);
this.setViewBinder(new SmsViewBinder());
}
}
public class SmsViewBinder implements ViewBinder {
private static final String TAG = "SmsViewBinder";
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if(view instanceof TextView) {
int amount = cursor.getInt(4);
NumberFormat nfs = NumberFormat.getInstance();
String strValue = nfs.format(amount);
((TextView)view).setText(strValue);
return true;
}
return false;
}
}
했더니 전부 저렇게 나오네요
날짜 주유량 가격
9,000 9,000L 9,000원
따로따로 TextView 를 설정하는 방법을 잘모르겠습니다
알려주세요~
===원래질문===========================================================================
1. 첫번째 질문입니다 위에서 일단 ListActivity로 뿌려주고 있습니다(LIstView사용)
그리고 그밑에 Total은 따로 TextView로 뿌려주고 있구요
String[] from = new String[] {"JUYUDATE" , "LITER" , "MONEY"};
int[] to = new int[] { R.id.juyu_list_DATE
, R.id.juyu_list_LITER
, R.id.juyu_list_MONEY};
SimpleCursorAdapter juyu_list = new SimpleCursorAdapter(this,
R.layout.juyu_list, cursor, from, to);
//가져온 커서의 내용에서 가격을 전부 가져와 합하여 준다
for(int i=0 ; i<juyu_list.getCursor().getCount() ;i++){
totalValue+=(int)cursor.getInt(4);
cursor.moveToNext();
}
//가격의 총합을 넘버포멧으로 변경하여 세자리마다 ' , '를 찍어준다
NumberFormat nf = NumberFormat.getInstance();
String strTotalValue = nf.format(totalValue);
//출력한다(Total)
total.setText(strTotalValue+"");
//커서로 불러온 리스트를 출력한다
setListAdapter(juyu_list);//여기서 뿌려준것은 가격이 Integer로 DB에 들어가 있습니다
머 이런식인데
Total처럼
위에서 리스트로 뿌려주는것을
9000 => 9,000 이런식으로 뿌여주고 싶은데
어떻게 커서로 불러온것을 수정해야할지모르겠네요
저방식으로는 수정이 불가능한지요??
아니면 DB에서 불러와서 뿌려주는 방식이 저방식말고
다른것으로 해야하는지요 또 그것은 어떤것이 있는지 알고 싶습니다