How can I make bold and italic the Branch Name:, Branch No:, Branch Phone No: and Branch Timings: in Java code? The database data should remain in simple format. These four are just headings of them. In this (current) case, it prints/displays the whole data in simple format and the user has a problem reading this data.
String branchInfoString = "" ;
// fetching all the database data in a list
List<BranchInfo> dbDataList = _dbHandler.getAllInfo() ;
// getting that data into a string that will be displayed in TextView
for(BranchInfo aBranch : dbDataList ){
branchInfoString = branchInfoString +
"Branch Name: " + aBranch.getBranchName() + "\n" +
"Branch No: " + aBranch.getBranchNo() + "\n" +
"Branch Phone No: " + aBranch.getBranchPhone() + "\n" +
"Branch Timings: " + aBranch.getBranchTiming() + "\n" +
"\n --------------------------------------- \n \n" ;
}
// showing all the branch data in a text_view
setContentView(R.layout.db_branch_list) ;
TextView dbDataView = (TextView)findViewById(R.id.db_branch_list) ;
dbDataView.setText(branchInfoString) ;
Yes, you can decorate the text in your TextView using HTML tags. That includes not just italics and bold, but also font color, and some other stuff. Something like this:
branchInfoHtmlString = branchInfoString +
"<b>Branch Name: " + aBranch.getBranchName() + "</b>\n" +
"<i>Branch No: " + aBranch.getBranchNo() + "</i>\n" +
"<font >Branch Phone No: " + aBranch.getBranchPhone() + "</font>\n" +
"<font color="#FFDDDDDD">Branch Timings: " + aBranch.getBranchTiming() + "</font>\n" +
"\n --------------------------------------- \n \n" ;
}
// showing all the branch data in a text_view
setContentView(R.layout.db_branch_list) ;
TextView dbDataView = (TextView)findViewById(R.id.db_branch_list) ;
dbDataView.setText(Html.fromHtml(branchInfoHtmlString)) ;
Not all HTML tags are supported, you can find the lists of tags here and here.
Use HTML content to format your text for example:
branchInfoString = branchInfoString +
"<b><i>Branch Name: </i></b>" + aBranch.getBranchName() + "\n" +
"Branch No: " + aBranch.getBranchNo() + "\n" +
"Branch Phone No: " + aBranch.getBranchPhone() + "\n" +
"Branch Timings: " + aBranch.getBranchTiming() + "\n" +
"\n --------------------------------------- \n \n" ;
dbDataView.setText(Html.fromHtml(branchInfoString ));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With