I want to integrate text widget in my application in android studio. I tried running the samples and they are working fine. Now i want to toast the digital text that appears after user input. I want to save that text somehere. I used this code in OnRecognitionEnd() function
#Override
public void onRecognitionEnd() {
String Result = mEditText.getText().toString();
Log.d(TAG, "result is: " +Result);
}
Now can you kindly tell me I want to display the text that is being stored in “Result” I used multiple ways but it says UNFORTUNETLY THE APPLICATION HAS STOPPED. For Example i simply did this
TextView textElement = null;
textElement.setText(Result);
Please tell me what I am doing wrong what should i do to display it ?
If you do this :
TextView textElement = null;
textElement.setText(Result);
You will try to setText on null. I suppose the error in your logcat is NullPointerException.
You have to instantiate your textElement.
TextView textElement=(TextView)findViewById(R.id.myid);
Where "myid" is the id in your layout.xml.
Related
I'm completely new to Android Studio.
I have just installed it on Windows 10 and since I wanted to learn how to use it, I have started to follow the online guide (https://developer.android.com/training/basics/firstapp/starting-activity.html#Up).
I am literally following it step by step, but when it comes to this part of the code:
public class DisplayMessageActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
// Get the Intent that started this activity and extract the string
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
// Capture the layout's TextView and set the string as its text
TextView textView = (TextView) findViewById(R.id.textView);
textView.setText(message);
}
the "textView" part after "findViewById" appears red and I get this error message: "cannot resolve symbol 'textView'".
This happens even if I have imported android.widget.TextView.
Maybe this is stupid question, but I am completely new to Android Studio.
Thanks for the answers :)
In your file R.layout.activity_display_message, the <TextView> tag must have android:id="#+id/textView"
Can you include your XML File?
As mentioned by buutqn
<TextView> tag must have android:id="#+id/textView"
This is in the file: app.res.layout.activity_display_message.xml
under the Text tab(as opposed to Design tab).
This issue can be duplicated by deleting the TextView box from the design tab, and inserting a new (second) text view.
In my case, the problem was for other reason although the error was the same. I copied the following code out of the OnCreate method.
// Get the Intent that started this activity and extract the string
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
// Capture the layout's TextView and set the string as its text
TextView textView = findViewById(R.id.textView);
textView.setText(message);
The text (TextView) before findViewById was not neccesary.
The TextView object of the Activity_display_message is called TextView2, instead of Textview. So I tried and changed:
TextView textView = (TextView) findViewById(R.id.textView);
for
TextView textView = (TextView) findViewById(R.id.textView2);
And it worked!
Erase the statement, then retype it. There is going to be a small pop up indicating you to press a command. It is basically an import library issue when you press the command (for macOS it is ⌥⏎ ) the respective library will be added. If this does not work, close Android Studio and reopen it . I am not an expert on this matter, but this worked for me hence I am sharing.
After tiresome searches and updating settings,
I Just clicked Invalidate Catches -> Invalidate And Restart
And Done! TextView Error Disappearedenter image description here
I am trying to develop an android app via vuforia sdk and unity.
The app should:
detect a string and as soon as the string is detected, will play video on video prefabs (not full screen).
However, I could not figure out where in TextEventHandler.cs is handling whether text is detected...
Sorry guys.. i forgot to post code..
below was what I found in TextEventHandler that vuforia provides to me...
I was guessing maybe this is handling whether the text is detected or not
// Once the text tracker has initialized and every time the video background changed,
// set the region of interest
if (mVideoBackgroundChanged)
{
TextTracker textTracker = TrackerManager.Instance.GetTracker<TextTracker>();
if (textTracker != null)
{
CalculateLoupeRegion();
textTracker.SetRegionOfInterest(mDetectionAndTrackingRect, mDetectionAndTrackingRect);
//v.SetActive (true);
}
mVideoBackgroundChanged = false;
}
Use Text Recognition instead of this method. Visit here to see how to recognize text. And load your video when the text is recognized instead.
I don't know how to solve this issue,there are some strings needed to fill in the textview,"#Tony#Tom#James#Brown...",what I want to do is like following "#Tony #Tom #James #Brown..." this will be displayed in the textview,the spacing is also specified,for example,"20dp" is the distance between '#Tony' and '#Tom'.I don't know how to create a textview likes above,I have a another question,when the content is out of range,the content should start from next line,so do I deal with this problem?Thank you anyone who gives an answer. If I didn't discribe this question in detail,forgive me.
You can use https://android-arsenal.com/details/1/2242 .
<com.apradanas.simplelinkabletext.LinkableEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
// find username
Link linkUsername = new Link(Pattern.compile("(#\\w+)"))
.setUnderlined(false)
.setTextColor(Color.parseColor("#D00000"))
.setTextStyle(TextStyle.BOLD)
.setClickListener(new Link.OnClickListener() {
#Override
public void onClick(String text) {
// do something
}
});
more information is available on the android arsenal page
I decided to learn a little bit android progrramming and by using Eclipse + android plug-in I made an android "hello world" application. After that I tryed something simple and used 3 TextViews:
ID:TextView1 String-Value:A=5
ID:TextView2 String-Value:B=10
ID:TextView3 String-Value:A+B=C=
I created them in main.xml menu by drag and drop so, to show them I'm using the flowing line:
setContentView(R.layout.main);
The Question is: I want to get string values of A and B and append the result of 5+10 to the string value of C actualy I did it but it take too much codes just for get str value of a TextView and editing it. Is there any short way like in .Net?
string Str = This.Label1.Text();
And is eclipse is the best IDE or am I should use something else?
When I have several textviews etc, Why am I should write unnecessary lines if there is a short way to do it.
Another Question is I get str-value of B which is 10 but when I tryed the same thing for A it says there is nothing inside VarAStr
*My Codes are:*
setContentView(R.layout.main);
TextView VarAStr = (TextView)findViewById(R.id.VarA);
TextView VarBStr = (TextView)findViewById(R.id.VarB);
TextView VarC = (TextView) findViewById(R.id.VarC);
try{
int VarA=Integer.parseInt(VarAStr.getText().toString().substring(2));
int VarB=Integer.parseInt(VarBStr.getText().toString().substring(2));
VarC.append(String.format("%d", (VarA+VarB)));
}
catch(Exception e){
Toast.makeText(this, e.toString() + " -" + VarAStr.getText().toString() + "-", Toast.LENGTH_LONG).show();//Show();
}
For the last question I found a bad code line in main.xml :) wich has no android:text="#string/VarA" I added this and problem solved.
Thank you for any respond.
You can always put the repeated code on a function that returns a string.
Something like:
public String getTextOfView(int id) {
TextView tmp = (TextView)findViewById(id);
return tmp.getText.toString();
}
I have a audio file and I want to read this text file with highlight the text.Can I do this.Please help me.
You might begin by reading some introductory documentation on the Text to Speech the Android class android.speech.tts.TextToSpeech at http://developer.android.com/reference/android/speech/tts/TextToSpeech.html
With this class you may have your app to easily speak from text. You just create an instance of the class, wait for it to complete its initialization, and speak. Something along this, just to get you started.
import com.google.tts.TTS;
...
private TTS myTts;
...
myTts = new TTS(this, ttsInitListener, true);
...
private TTS.InitListener ttsInitListener = new TTS.InitListener() {
public void onInit(int version) {
myTts.speak("Hello world", 0, null);
}
};
Things will get more complex when you try to change the "Hello world" by the actual text read from your text file while highlighting the text on screen. I leave it as an exercise for you.