I have a TextView in my application. I want to align 2 separate text one ontop of the other.
But have no idea how. Any suggestions ?
Text code that is to be displayed:
String[] product_showcase_list = new String[] {
"Product Name 产品名称 : Office Chair 1 " +
"Product Serial 产品号码 :0C012345",
...
}
code that is used to call out String text:
label_col_1_datatab3.setText(product_showcase_list[cnt]);
Currently, what is being displayed on the screen:
Product Name 产品名称 : Office Chair 1 Product Serial 产品号码 :0C012345
How it is needed to be displayed:
Product Name 产品名称 : Office Chair 1
Product Serial 产品号码 :0C012345
Try adding "\n" after your number one. In your String
"Product Name 产品名称 : Office Chair 1 \n" +
"Product Serial 产品号码 :0C012345"
Or Use two TextViews in a LinearLayout or ListView
Within your loop, change as below.
String temp = product_showcase_list[cnt] + "\n"
label_col_1_datatab3.setText(temp);
Hope it helps!
Related
I have multiple value in single string, but I want to send in every string value on new line. I have written the following code, but it's not working.
String text ="Address" + strpropertyAddress +"\n"+ "Price" + strPrice;
This is my service method where i pass the string.
sendPropertyApi(text, sendto);
I have checked every where, and it is exactly same. Basically the string data should be sent in on a new line, but it's sent in on a single line.
Assuming(Because of Android tag) you are setting this text in textView or editText, for that I think you have to escape \. So use \\n instead. Try following:
String text ="Address" + strpropertyAddress +"\\n"+ "Price" + strPrice;
Or it is always better to use default line separator like following:
String text ="Address" + strpropertyAddress +System.getProperty("line.separator")+ "Price" + strPrice;
1.I am getting data from server storing inside string Array.
2.then i want to show in Android TextView ,each TextView line should Contain 2 strings(Like Skill Sets) from String array.
3.then need to add cross Image in right side of the Textview.
please help me, how to achieve this.
String mystring = "This is my first sentence";
String arr[] = mystring.split(" ", 3);
String firstWord = arr[0]; //This
String secondWord = arr[1]; //is
String theRest = arr[2]; //my first sentence
yourtextview.setText(firstWord +" "+ secondWord);
and regarding for Image in right side of the Textview put this in ur txtview'sxml.
android:drawableRight="#drawable/image"
If anyone could assist me with this little hiccup i'm having i would be grateful. Thanks in advance.
I have an app structure made from fragments and activities...
The main fragment is called "Headlines" - this displays to the user a list of words in a clickable list.
The detail view page for that is called "Articles" and the activity holding the data which is a list of words is called "Greetings".
Pretty much - in the articles activity;
I have: a List of words, the translated form of the words, synonyms etc and they are all stored using string arrays.
Once a word is selected, it launches the "details activity page" displaying more information on the selected word.
I want to be able to input a sound button here that allows the user to hear the translated word when pressed.
Note:
I have already placed the image button in the xml file for the final output, so it is viewable on whenever a user selects a word. I just need to program the button to be functional now.
The code below is where i have the list of words stored:
package com.example.sample;
public class GreetingsWords {
static String[] Headlines = {
"Hello",
"Goodbye",
"Good Morning",
"Good Night",
};
static String[] Articles = {
//word 1
"'Hello' \n\n\n " +
"Translation: Yow! \n\n" +
"Pronouncation: [Yoh'ow] \n\n" +
"Synonyms: Greetings!, Hello!, Hi, Hey \n\n",
//word 2
"'GoodBye' \n\n\n " +
"Translation: Lata \n\n" +
"Pronouncation: [lay'ta] \n\n\n" +
"Synonym: Likkle More. \n\n" +
"Pronouncation: [lickle- mor']",
//word 3
"'Good Morning' \n\n\n " +
"Translation: Mawnin \n\n" +
"Pronouncation: [Maw-ning] ",
//word 4
"'Good Night' \n\n\n " +
"Translation: Nighty Nights \n\n",
};
}
I am working on an android project and came to a halt in my design process. I am a beginning java programmer and also new to the android sdk so please bear with me... On my main screen, it prompts the user to make 6 selections from separate spinner drop down menus. Each of the 6 spinners contain the same StringArray. What I want to do is display the 6 different spinner selections within an EditText field on another screen when a 'submit' button is clicked. I have the submit button listener set up correctly along with a new activity and intent to switch the layout to the output screen. What I don't understand is how to take the spinner(s) and display them into the text fields. I have tried setting up 6 individual SetOnItemSelectedListener methods but unsure if that is allowed. Help, please and thank you!
I sugggest you setup your spinners with a simple ArrayAdapter like so:
String[] selections = new String[] { "Selection 1", "Selection 2", "Selection 3", "Selection 4" };
ArrayAdapter<String> myAdapter = new ArrayAdapter<String>(mySpinner1.getContext(), android.R.layout.simple_spinner_item, selections);
myAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mySpinner1.setAdapter(myAdapter);
Follow the same concept for all 6 spinners. And then when you fetch their values like so:
String value1 = mySpinner1.getSelectedItem().toString();
String value2 = mySpinner2.getSelectedItem().toString();
String value3 = mySpinner2.getSelectedItem().toString();
String value4 = mySpinner2.getSelectedItem().toString();
String value5 = mySpinner2.getSelectedItem().toString();
String value6 = mySpinner2.getSelectedItem().toString();
Now you can concatenate these string as needed and display them in your text view like so:
myTextView.setText(value1 + "," + value2 + "," + value3 + "," + value4 + "," + value5 + "," + value6);
Hope that helps. Have fun.
Here's my issue:
I have a database and it is full of episodes of a tv show. One column denotes the episode number. I want to display the episodes in a list like this:
Episode 1
Episode 2
Episode 3
etc.
I'm using my own adapter class that extends SimpleCursorAdapter to do this...
Since I had formatting errors I am using Android.R.layout.simple_list_item_1 and Android.R.id.text1
Basically the only reason I have a custom adapter is so I can do something like this:
textView.setText("Episode " + cursor.getString("column_for_episode_number");
The problem is, I get a list that looks like this:
Episode
1
Episode
2
Episode
3
When I try something like this(which worked in a different portion of my code):
String text = "Episode " + cursor.getString("blah");
text = text.replaceAll("\\n","");
I get the exact same list output :(
Why don't I use create a custom view with two textboxes next to each other? It is hard for me to get that to look pretty :/
text.replaceAll(System.getProperty("line.separator"), "");
There is a mistake in your code. Use "\n" instead of "\\n"
String myString = "a string\n with new line"
myString = myString.replaceAll("\n","");
Log.d("myString",myString);
Check if there is new line at the beginning before you replace and do the same test again:
for(int i=0; cursor.getString("blah").length()-1; i++)
{
if(cursor.getString("blah").charAt(i)=='\\n') <-- use the constant for the line separator
{
Log.i("NEW LINE?", "YES, WE HAVE");
}
}
Or use the .contains("\n"); method:
Check the xml for the width of the textview as well.
Why are you using getString() when you are fetching an integer? Use getInt() and then use Integer.toString(theint) when you are setting the values in a textview.
This could help you:
response = response.replaceAll("\\s+","");
It sounds like you are hitting wrapping issues rather than newline issues. Change this:
String text = "Episode " + cursor.getString("blah");
To this:
String text = "Episode" + cursor.getString("blah");
And see if that changes the output. Post your layout xml please?
this worked for my (on android 4.4):
(where body is a string with a newline entered from an EditText view on handset)
for (int i=0; i<body.length(); i++) {
if (body.charAt(i) == '\n' || body.charAt(i) == '\t') {
body = body.substring(0, i) + " " + body.substring(i+1, body.length());
}
}
have you tried
cursor.getString("blah").trim()