저는 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
}
, 버튼의 텍스트가 잘
을 일치하지 않습니다(그냥 내 앱의 스크린 샷을 게시하는 데 충분한 평판이 없다는 것을 깨달았습니다.)
오래 동안 디버깅하려했지만 아직 단서가 없습니다. 어떤 도움을 깊이 감사드립니다!
편집 : 스크린 샷
는
나는이 링크를 사용하여 String.Format을 사용하는 방법을 알아야한다고 생각한다. @stackoverflow.com/questions/3695230/how-to-use-java-string-format –
@CuongHuynh 잘 했어. 그래도 틀렸어? – TheInvisibleFist
내 잘못. 열/텍스트 뷰 너비에 문제가 있습니까? –