android.widget.TextView.setTextAlignment(): java.lang.NoSuchMethodError - java

Situation:
I have a TextView that have the property
android:textAlignment="center"
I am generating another TextView dinamically, based on my TextView from XML Layout, using a clone, cloning all the basic properties to work the way above.
Problem:
To do this i need to use this method:
this.myTextView.setMyTextViewProperty(MyTextView.getMyTextViewProperty());
for example:
this.MyTextView.setText(MyTextView.getText());
Note that this.MyTextViewis a local variable and MyTextView is a private var declared on the top of the file, under class name.
I do this on all the properties of the TextView but when i hit the following line of code from the TextAlignment property...:
this.myTextView.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
I tried to set it to a Custom Aligment instead of getting from my XML TextView It gives me an error:
11-20 15:27:04.460: E/AndroidRuntime(9185): FATAL EXCEPTION: main
11-20 15:27:04.460: E/AndroidRuntime(9185): java.lang.NoSuchMethodError: android.widget.TextView.setTextAlignment
But i see on Ctrl + Space that the method exists, so i cant understand what is happening.
A second try was, to set my TextView property to the property that comes from my TextView:
this.myTextView.setTextAlignment(MyTextView.getTextAlignment());
With no success, too.
Obs: i do not want a Android XML Layout solution, i want a solution on code, because i generate the TextView dinamically on the Activity
I'm using API Level 15
Any help?

The setTextAlignment method was added in API level 17. Maybe your compiler in the IDE is above 17 and the device/emulator which you are testing is less than that. Here the link to setTextAlignment.
Added from the comments:
For API level 15 and below, you want setGravity, per this question.

Related

Arabic data fetched from Microsoft SQL is not showing properly

I developed a web service using java which request from the database Arabic data.
I'm using this web service in android using volley.
The problem is when i get the data and set it in text field it's show some weird symbols (اÙÙÙسÙ).
The collation in database is : Arabic_CI_AS
I tried many solutions but nothing works!
I would really appreciate your help
This might be related to text direction attribute for the TextView, you have to set it to "anyRtl". Not sure which version that you are working on but this is available since 17+.
This above attribute can be set in one of the following ways:
From XML: Add this line: android:textDirection="anyRtl" to your
TextView tag.
From code:
textview.setTextDirection(View.TEXT_DIRECTION_ANY_RTL);
Haven't tried it though, hope this helps.
Few Links:
https://android.stackexchange.com/questions/25359/how-to-make-an-android-device-to-display-complex-rendering-of-indic-characters
Display Arabic text in android textview
https://developer.android.com/reference/android/text/TextDirectionHeuristics

PeerConnectionFactory in Android Studio 2 has no methods

After adding compile 'org.webrtc:google-webrtc:1.0.+' to my build.gradle file I try to init PeerConnectionFactory, but this class has no any useful methods.
What am I doing wrong?
UPDATE:
enter image description here
The last version org.webrtc:google-webrtc:1.0.21217
You can init by following codes
PeerConnectionFactory.InitializationOptions.Builder optionBuilder =
PeerConnectionFactory.InitializationOptions.builder(/* Put context here */);
optionBuilder.setEnableInternalTracer(true);
optionBuilder.setFieldTrials("WebRTC-FlexFEC-03/Enabled/");
optionBuilder.setEnableVideoHwAcceleration(true);
PeerConnectionFactory.initialize(optionBuilder.createInitializationOptions());
First, try to use an specific version like: compile 'org.webrtc:google-webrtc:1.0.20198'
And then make sure you rebuild your project (not only refresh gradle, since it might not be enough for the autocomplete to work).
In your screenshot, it looks like you are trying to autocomplete outside of any method. Since Android Studio tries to only show you valid stuff, it won't display the other methods unless you write it on a valid context (i.e.: inside of some method's implementation).

Android get id for an edit text field from a context xml file

I have an activity called PeopleActivity, with a layout xml of activity_people.xml.
This activity is using the Android Studio Navigation Drawer Activity template.
I have a list view in the content_people.xml file named people_list. When I attempt to associate this control in the back end, it is unable to find the id. I am attempting it as:
peopleList = (ListView) findViewById(R.id.people_list);
Any insight would be greatly appreciated.
EDIT: Did an update to the code section to reflect the correct control referenced.
you should declare your listview like this:
peopleSearch = (ListView) findViewById(R.id.people_list);
not as EditText
I found the answer. You cannot use capital letters in the naming of your controls. Once I fixed this, everything worked fine.

How do I get specific line text in a textview and use webview to load the text(url)

Recently I want to get specific line text in a textview and I want to use a webview to load the text,I ve found some code references which I think is useful but not work for me well.
Textview:
A
Http://ABC.com.jp
C
I want to load line 2 URL.
Sorry for my low responsibility, now I still updating and modifying my source code,I am new in java and this is not my main profit,besides I will keep learning.
Target =(TextView)findViewbyid(R.id.abc);
myTextView = (TextView)findViewbyid(R.id.id1);
int startL= myTextView.getLayout().getLineStart(2);
//^start line
int endL = myTextView.getLayout().getLineEnd(3);
//^end line
String getResults = myTextView.getText().substring(startL, endL);
Target.setText(getResults);
//benefits of using get line end & start is that it can select multiple line content from a large content,also it can be used in selecting single line or specific line.

Android development toggling TextView visibility

Im having some trouble with setting textview to invisible/visible.
basicly i want this to happen when an on/off button has been clicked.
what i did is kind of like
textview.setVisibility(TextView.VISIBLE);
textview.setVisibility(TextView.INVISIBLE);
when i try executing this the emultor says that the app has stopped unexcpetedly
Are you building this from XML or programmatically?
I would make it with an XML file then when the Activity runs change the property. Be sure to use setContentView(R.layout.main); before you try to get the TextView with findViewById(...).
Call .setVisibility(View.GONE); on the TextView to hide it.
Call .setVisibility(View.VISIBLE); to on the TextView to show it.
I have an example that does something like this. You can see the code here: https://github.com/ethankhall/Morse-Messenger/blob/master/src/com/kopysoft/MorseMessenger/Translate.java
Without more code or a stack trace, it's hard to say, but it sounds like you haven't initialized the text view. Here's how to do it:
TextView myTextView = (TextView) findViewById(R.id.tv_text);
Where 'tv_text' is the id of the textview as defined in the xml layout file.
Hope that helped!
Read about DDMS and logcat to obtain a stacktrace and to see what the problem is: http://developer.android.com/guide/developing/debugging/debugging-projects.html
This is what you are looking for:

Categories