I've got a question. text. for example
String str = "line1"+"\n" +
"line2"+"\n" +
"line3"+"\n" +
"line4"+"\n" +
"line5"+"\n" +
"line6"+"\n" +
"line7"+"\n" +
"line8"+"\n" +
"line9"+"\n" +
"line10"+"\n" +
"line11"+"\n" +
"line12"+"\n" +
"line13"+"\n" +
"line14"+"\n" +
"line15"+"\n" +
"line16"+"\n" +
"line17"+"\n";
I have a component that creates the page.
I need my text is divided into blocks (pages) and place it on the page.
Now I work like that. I break the text into lines, and each page can place the line. But I need to break up the text such as 20 lines per 1 page. and these blocks of 20 lines displayed on a separate view. Now I work as follows:
LayoutInflater inflater = LayoutInflater.from(this);
List<View> pages = new ArrayList<View>();
String[] str1 = str.split("\n");
View[] page1 = new View[7];
TextView[] textView1 = new TextView[7];
for (int i=1;i<page1.length;i++){
page1[i] = inflater.inflate(R.layout.page, null);
textView1[i] = (TextView) page1[i].findViewById(R.id.text_view);
textView1[i].setText(str1[i+1]);//then I do not need one row and 20
pages.add(page1[i]);
}
Related
So I want to have a headline that is ALWAYS a third of the screen and then the rest of the 2 thirds of the screen with names. Seems easy but the result is that the headline becomes less than a third if there is many names. It is only 2 lines that does this I wrtite //1 //2 to easily find them but give the whole code since it may affect the result.
Here is a photo.
The top text does not show the whole message and Is not 1 third of the screen as intended
Thanks in advance!
private void showScores() {
float baseTextSize = 100/playerNum;
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT,
10000.0f //1
);
TextView t = new TextView(this);
String result_msg = getString(R.string.result_msg);
t.setLayoutParams(param);
t.setText(result_msg + "\n");
t.setTextColor(getColor(R.color.white));
if (playerNum>3) {
t.setTextSize(30f);
} else {
t.setTextSize(40f);
}
scoreShower.addView(t);
param.weight = 20000.0f/playerNum; //2
for (int i=0;i<playerNum;i++) {
TextView txt = new TextView(this);
txt.setLayoutParams(param);
if (i == 0) {
txt.setTextSize(baseTextSize + 8f);
txt.setTextColor(getColor(R.color.gold));
} else {
txt.setTextSize(baseTextSize);
txt.setTextColor(getColor(R.color.white));
}
String txtString = (i+1) + ". " + arrayList.get(i).getKey() + " : " + arrayList.get(i).getValue();
txt.setText(txtString);
if (playerNum>6) {
txt.setTextSize(10f);
}
scoreShower.addView(txt);
}
Try using weighted LinearLayout
<LinearLayout
....
...weightSum="3"
...orientation="vertical">
Set the weight of the top view to 2 using
<...
...layout_weight="1">
And the one below set the weight to 2
I'm trying to remove a single view from layout but it is not being removed.
But, when i call removeAll, it does remove them all.
Here is the code:
for (int subspe = 0; subspe < totalSubSpe; subspe++) {
View childSubSpe =
BasicInfoUpdateDocProfile.ll_custom_for_supspecialist.getChildAt(subspe);
TextView subSpecialityId = (TextView) childSubSpe.findViewById(R.id.tv_speciality_id);
TextView specialistId = (TextView) child.findViewById(R.id.tv_id);
String speID = specialistId.getText().toString();
String subSepId = subSpecialityId.getText().toString();
Log.e("TAG", "the the the the id is: speciality " + speID);
Log.e("TAG", "the the the the id is: sub speiciality " + subSepId);
if (speID.equals(subSepId)) {
//removing sub qualificaiton
Log.e("TAG", "It is Equal subspecialist ");
ViewGroup par = (ViewGroup) childSubSpe.getParent();
par.removeView(childSubSpe);
//BasicInfoUpdateDocProfile.ll_custom_for_supspecialist.removeView(childSubSpe);
BasicInfoUpdateDocProfile.ll_custom_for_supspecialist.
removeView((View)childSubSpe.getParent());
// BasicInfoUpdateDocProfile.ll_custom_for_supspecialist.removeAllViews();
}
}
I have 4 textviews which take their values from dropdown list (spinner) selected at previous screen.
There can be either 2 or 4 numbers/letters as result of this selection.
The first position will always be a number and the second position will always be a letter. The third position can be a number or blank and the fourth position can be a letter or blank.
If position 3 and position 4 are blank then I need to make them equal to positions 1 & 2 respectively.
String myGrade = intent.getStringExtra("parameter_name_grade");
// above takes value of 'myGrade' from spinner selection at previous screen
String mDisplayGradeNumberEff = (" " + myGrade.charAt(0));
TextView displayGradeNumberEff = (TextView) findViewById(R.id.gradeNumberEffTV);
displayGradeNumberEff.setText(mDisplayGradeNumberEff);
String mDisplayGradeLetterEff = (" " + myGrade.charAt(1));
TextView displayGradeLetterEff = (TextView) findViewById(R.id.gradeLetterEffTV);
displayGradeLetterEff.setText(mDisplayGradeLetterEff);
// above works correctly
// from here down only works when a character is present in both positions
// if positions 3(2) and 4(3) are empty app stops running.
String mDisplayGradeNumberDia = (" " + myGrade.charAt(2));
if (mDisplayGradeNumberDia.isEmpty()) {
mDisplayGradeNumberDia = mDisplayGradeNumberEff;
}
TextView displayGradeNumberDia = (TextView) findViewById(R.id.gradeNumberDiaTV);
displayGradeNumberDia.setText(mDisplayGradeNumberDia);
String mDisplayGradeLetterDia = (" " + myGrade.charAt(3));
if (mDisplayGradeLetterDia.isEmpty()) {
mDisplayGradeLetterDia = mDisplayGradeLetterEff;
}
TextView displayGradeLetterDia = (TextView) findViewById(R.id.gradeLetterDiaTV);
displayGradeLetterDia.setText(mDisplayGradeLetterDia);
}
I Guess you have a array out of bounds exception, please provide Logcat....
Check if "myGrade" has 3/4 Characters, if it does not you can't read them with charAt(3)...
You can check the length of the String with "myGrade.length()"
When I asked this question I was fairly new to the site and didn't understand that I should post back the solution for future reference. Solution below worked so thanks to rocket for your help and sorry for the delay!
int myGradeLength = mGrade.length();
if (myGradeLength != 4) {
mDisplayGradeNumberEff = ("" + mGrade.charAt(0));
mDisplayGradeLetterEff = ("" + mGrade.charAt(1));
mDisplayGradeNumberDia = ("" + mGrade.charAt(0));
mDisplayGradeLetterDia = ("" + mGrade.charAt(1));
} else {
mDisplayGradeNumberEff = ("" + mGrade.charAt(0));
mDisplayGradeLetterEff = ("" + mGrade.charAt(1));
mDisplayGradeNumberDia = ("" + mGrade.charAt(2));
mDisplayGradeLetterDia = ("" + mGrade.charAt(3));
}
Getting value for only single Item in TextView from CartActivity, but want to fetch detail for all Item(s) placed in Cart
Like: I have 4 items in Cart, but once i am trying to show these item details in another activity, so here i am only getting single item detail (only for 4th Item, not for all fours) why?
CODE:
for (int i = 0; i < Session.sItem_Detail.size(); i++) {
String title=Constants.sItem_Detail.get(i).get(
ProductInformationActivity.KEY_TITLE);
String qty=Constants.sItem_Detail.get(i).get(
ProductInformationActivity.KEY_QTY);
String cost=Constants.sItem_Detail.get(i).get(
ProductInformationActivity.KEY_COST);
textDetails =(TextView)findViewById(R.id.txtDetails);
textDetails.setText("(Title:" +title + "(Qty:" + qty + ")" + "(Cost:" + "Rs." + cost + ")");
public class Session {
public static ArrayList<HashMap<String, String>> sItem_Detail = new ArrayList<HashMap<String, String>>();
}
So here is my question, how can i get item details for all items stored in Cart, not just for one..
Try this
use append(charctersequence) instead of setText(charctersequence)
textDetails.append("(Title:" +title + "(Qty:" + qty + ")" + "(Cost:" + "Rs." + cost + ")"+"\n");
I'm not sure how to handle that. I need linear layout which needs to have 20+ TextView and EditText components. I can define ImageView and buttons on top but I don't know how to generate rest of the components below and then put a button at the end.
It will look something like this:
---Button-----Button-------
--------ImageView----------
TextView -------- EditText
Item1.............[-------]
Item2.............[-------]
Item3.............[-------]
Item4.............[-------]
.
.
.
------------Button------------
There will be really a lot of components so I would like to avoid defining all components by hand in XML. After clicking on button all components need to be saved in pairs "name":"value" ("Item1":"EditText value"). I have a list of item's names and user will write the values for those items and save them to JSON file.
Thank you in advance.
you have to implement a class like this.
public class DetailedTicketSystemView extends LinearLayout
{
static int inc = 100;
ArrayList<XmlScommessaInCorso> _viewData;
ArrayList<xmlSistemaMovimenti> _systems;
Context _context;
public DetailedTicketSystemView(Context context, int res, AttributeSet attrs, ArrayList<XmlScommessaInCorso> viewData, ArrayList<xmlSistemaMovimenti> systems)
{
super(context, attrs);
_context = context;
_viewData = viewData;
_systems = systems;
LayoutInflater.from(context).inflate(res, this, true);
setId(inc);
inc++;
setLayout();
}
private void setLayout()
{
TextView textView;
String text;
for (int i = 0; i < _systems.size(); i++)
{
View quotesView = (View) LayoutInflater.from(_context).inflate(R.layout.row_ticket_detail_system_layout, null, true);
quotesView.setId(i);
// System Id
textView = (TextView) quotesView.findViewById(R.id.systemId);
text = "" + _context.getString(R.string.id_sistema) + " " + _systems.get(i).getAttributeOrVoidString(xmlSistemaMovimenti.ATTR_id) +
" / " + _viewData.size();
textView.setText(text);
// System Columns
textView = (TextView) quotesView.findViewById(R.id.systemColumns);
text = "" + _context.getString(R.string.colonne) + " " + _systems.get(i).getAttributeOrVoidString(xmlSistemaMovimenti.ATTR_n_multiple_sis);
textView.setText(text);
// System Bet Text
textView = (TextView) quotesView.findViewById(R.id.systemBetText);
textView.setText(R.string.importoPerColonna);
// System bet Value
textView = (TextView) quotesView.findViewById(R.id.systemBetValue);
text = "€ " + XmlScommessaInCorso.getQuotaFormattedOrVoid(_systems.get(i).getAttributeOrVoidString(xmlSistemaMovimenti.ATTR_impo_sistema));
textView.setText(text);
LinearLayout primaryLayout = (LinearLayout) findViewById(R.id.primaryLayout);
primaryLayout.addView(quotesView);
}
}
}