Android Question Set edittext content using inline Java

prajinpraveen

Active Member
Licensed User
Longtime User
Good Day,

I have a scenario where i have to use Java to set content of a edit text or a label. I have tried using the code below.
There is an error on line

this.tv_message = (TextView) findViewById(android.R.id.ed_tv1);
this.tv_message.setText("hello");



javacode:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private ed_tv1 As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout")  
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

#If JAVA
import android.view.*;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
private TextView tv_message;
 
public void Test() {
    setProgressBarIndeterminateVisibility(true);
}
public void _onCreate() {
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
}
public void _onResume() {
    processBA.Log("OnResume");
   
    this.tv_message = (TextView) findViewById(android.R.id.ed_tv1);
    this.tv_message.setText("hello");
}
public void _onPause() {
    processBA.Log("onPause");

}
public void _onDestroy() {
    processBA.Log("_onDestroy");
}
public void _onStop() {
    processBA.Log("_onStop");
}
public void _onStart() {
    processBA.Log("_onStart");
}
public void _onPrepareOptionsMenu (Menu menu) {
    processBA.Log("_onPrepareOptionsMenu");
}
public boolean _onCreateOptionsMenu (Menu menu) {
    processBA.Log("_onCreateOptionsMenu");
    return false;
}
#End IF
 

prajinpraveen

Active Member
Licensed User
Longtime User
Hello Erel,

I have tried the following previously and the above was my option B.

Java Code:
processBA.raiseEventFromUI(this, "pos2" + "_fire", new Object[] {"100"});

I am calling an Activity of a thrid party app through an intent (POS for making payment). Once the action, either success or failure of the POS transaction, the control is returned back to my app. I use the "raiseEventFromUI" code. The B4A sub (pos2_fire) is never called and i get an message on the log, "ignoring event, pos2_fire". I am not sure if this is because the activity is Paused when the control is returned to my app
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
not going to work this way. you need to look into activityforresult. and you need to know for sure that the called activity returns a result. your app will handle it. examples available. if 3rd party app doesn't return a result, then calling it serves no purpose (nor does your raising an event)
 
Upvote 0

prajinpraveen

Active Member
Licensed User
Longtime User
not going to work this way. you need to look into activityforresult. and you need to know for sure that the called activity returns a result. your app will handle it. examples available. if 3rd party app doesn't return a result, then calling it serves no purpose (nor does your raising an event)
The target app will always return the results, success or failure message to the calling app (B4A) . Please can you direct me to a few examples. your assistance is highly appreciated
 
Last edited:
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
assuming the 3rd party app is using setresult(), you'll be fine.
i don't have a particular example in mind, sorry. there are plenty.
just type "activityforresult" in the search box. find a recent one and run it.
if it runs, and you follow what's going on, you'll be able to adapt it. if you
get stuck, i'm happy to tell you what i see. erel has set this particular
routine up to work very easily (as is usually the case). 2 or 3 little pieces, and
you're good to go.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
am calling an Activity of a thrid party app through an intent (POS for making payment). Once the action, either success or failure of the POS transaction, the control is returned back to my app. I use the "raiseEventFromUI" code. The B4A sub (pos2_fire) is never called and i get an message on the log, "ignoring event, pos2_fire". I am not sure if this is because the activity is Paused when the control is returned to my app
Switch to B4XPages. With B4XPages the pages are not paused when another activity is visible.
 
Upvote 0

prajinpraveen

Active Member
Licensed User
Longtime User
Thanks Erel. I will give this a try.

I have apps running on non B4XPages for over 10 years. Do you think they will be redundant in near future and I should start moving the apps to B4XPages design.

Thank you
 
Upvote 0

prajinpraveen

Active Member
Licensed User
Longtime User
figured out that a B4A sub can be called from inline java using an underscore ("_") before the name of the B4A sub.

code:
 try {
       _pos_fire(errorMsg);
    } catch (Exception e) {
        // Handle the exception here
        e.printStackTrace(); // or handle it in another way
    }

this worked for me. If this approach is correct, i will mark this question as Solved.
 
Upvote 0
Top