1

저는 Android 프로그래밍에 익숙하지 않습니다. 재무 관리 앱을 만들고 있습니다. .Android : setText로 포맷 된 문자열을 삭제합니다.

public String toString(int colWidth1, int colWidth2, int colWidth3) { 
    return String.format("%-" + colWidth1 + "s", myDisplayName) + 
      String.format("%-" + colWidth2 + "s", myBalance) + 
      String.format("%-" + colWidth3 + "s", myInterestRate); 
} 
: 현재 나는의 setText() 메소드는 내가 전달 문자열 형식을 파괴 문제에있어

을 나는 계정 정보의 형식화 한 문자열을 반환하는 관습 toString 메소드가있는 계정 클래스가

그리고 AccountInfo의 활동에 , 나는이 : 내가 원하는 나의 로그 캣 인쇄가 잘 문자열을 포맷 있지만

// create a table that contains all account information of the current user 
    TableLayout accountTable = (TableLayout) findViewById(R.id.tableLayout_account_details); 
    List<Account> accountList = accountManager.getAllAccounts(CurrentUser.getCurrentUser().getUserName()); 

    // for each account, display name, balance and interest rate 
    for (int i = 0; i < accountList.size(); i++) { 
     Account account = accountList.get(i); 
     TableRow accEntry = new TableRow(this); 
     Button accButton = new Button(this); 
     accButton.setText(account.toString(10, 10, 10)); 
     Log.i("account info", account.toString(10, 10, 10)); 

     // button format 
     TableRow.LayoutParams params = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 
     params.setMargins(0, -7, 0, -10); 
     accButton.setLayoutParams(params); 
     accButton.setGravity(Gravity.LEFT); 

     // add button to the row 
     accEntry.addView(accButton); 

     // add row to the table 
     accountTable.addView(accEntry); 

     // ...more code here for button click listener 
    } 

, 버튼의 텍스트가 잘

을 일치하지 않습니다

(그냥 내 앱의 스크린 샷을 게시하는 데 충분한 평판이 없다는 것을 깨달았습니다.)

오래 동안 디버깅하려했지만 아직 단서가 없습니다. 어떤 도움을 깊이 감사드립니다!

편집 : 스크린 샷

enter image description here

+0

나는이 링크를 사용하여 String.Format을 사용하는 방법을 알아야한다고 생각한다. @stackoverflow.com/questions/3695230/how-to-use-java-string-format –

+0

@CuongHuynh 잘 했어. 그래도 틀렸어? – TheInvisibleFist

+0

내 잘못. 열/텍스트 뷰 너비에 문제가 있습니까? –

답변

1

내 룸메이트는 문제를 지적한다! 그는 굉장해!

글꼴이 고정 폭이 아니기 때문에 맞춤이 꺼져 있습니다. 간단히

android:typeface="monospace" 

레이아웃 xml에서 문제가 해결되었습니다 !!!

0

나는 안드로이드 스튜디오에서 응답 할 :

이의 setText로 표시되는 텍스트을 연결하지 마십시오. 리소스 문자열을 자리 표시 자와 함께 사용하십시오.

호출 텍스트 뷰 #의 setText :

절대 형식 번호를 번호 # toString()를 호출; 분수 구분 기호와 로캘 별 숫자를 제대로 처리하지 못합니다. 적절한 형식 명세 (% d 또는 % f)와 함께 String # 형식을 사용하는 것을 고려하십시오.

텍스트를 표시하기 위해 문자열 리터럴 (예 : "Hello")을 전달하지 마십시오. 하드 코딩 된 텍스트를 다른 언어로 올바르게 번역 할 수 없습니다. Android 리소스 문자열을 대신 사용해보십시오.

텍스트 청크를 연결하여 메시지를 작성하지 마십시오. 이러한 메시지는 올바르게 번역 될 수 없습니다.