Hello everyone,
Developping an Android application, I would like to manage a click event from a Button object.
Here's the point : my source code is written in C++ (Qt) and my button in Java.
Can someone explain me how I can manage the click event between Java and Qt ?
Under the following form, compilation don't work.
Thanks!
myClass.cpp:
{
myFunction();
}
void MyClass::myFunction() {
QAndroidJniObject MyJavaClass;
MyJavaClass = QAndroidJniObject("org/qtproject/example/myproject/MyJavaClass",
"(Landroid/app/Activity;)V",
QtAndroid::androidActivity().object<jobject>()
);
}
MyClass::MyClass(QWidget *parent) : QWidget(parent)
{
myFunction();
}
void MyClass::myFunction() {
QAndroidJniObject MyJavaClass;
MyJavaClass = QAndroidJniObject("org/qtproject/example/myproject/MyJavaClass",
"(Landroid/app/Activity;)V",
QtAndroid::androidActivity().object<jobject>()
);
}
To copy to clipboard, switch view to plain text mode
MyJavaClass.java:
import ...
public class MyJavaClass {
private final Activity m_MainActivity;
public MyJavaClass(final Activity MainActivity)
{
m_MainActivity = MainActivity;
m_MainActivity.runOnUiThread(new Runnable() {
@Override
public void run()
{
RelativeLayout m_rlMainLayout;
m_rlMainLayout = new RelativeLayout(m_MainActivity);
m_MainActivity.setContentView(m_rlMainLayout);
ViewGroup.MarginLayoutParams mrgBtn;
ViewGroup.MarginLayoutParams mrgText;
TextView tvJavaText = new TextView(m_MainActivity);
tvJavaText.setText("Hello from Ui Thread!");
Button m_btn = new Button(m_MainActivity);
m_btn.setText("Hello Button");
m_btn.setOnClickListener(runningBtnClick);
m_rlMainLayout.addView(m_btn);
mrgBtn = (ViewGroup.MarginLayoutParams) m_btn.getLayoutParams();
mrgBtn.setMargins(150, 0, 0, 0);
m_btn.setLayoutParams(mrgBtn);
OnClickListener runningBtnClick = new OnClickListener() {
public void onClick(View v) {
mrgText.setMargins(150, 100, 0, 0);
tvText.setLayoutParams(mrgText);
tvText.setText("Hy, i clicked the button!");
System.out.println(m_btn.getLayoutParams().height);
}
};
}
}
}
}
import ...
public class MyJavaClass {
private final Activity m_MainActivity;
public MyJavaClass(final Activity MainActivity)
{
m_MainActivity = MainActivity;
m_MainActivity.runOnUiThread(new Runnable() {
@Override
public void run()
{
RelativeLayout m_rlMainLayout;
m_rlMainLayout = new RelativeLayout(m_MainActivity);
m_MainActivity.setContentView(m_rlMainLayout);
ViewGroup.MarginLayoutParams mrgBtn;
ViewGroup.MarginLayoutParams mrgText;
TextView tvJavaText = new TextView(m_MainActivity);
tvJavaText.setText("Hello from Ui Thread!");
Button m_btn = new Button(m_MainActivity);
m_btn.setText("Hello Button");
m_btn.setOnClickListener(runningBtnClick);
m_rlMainLayout.addView(m_btn);
mrgBtn = (ViewGroup.MarginLayoutParams) m_btn.getLayoutParams();
mrgBtn.setMargins(150, 0, 0, 0);
m_btn.setLayoutParams(mrgBtn);
OnClickListener runningBtnClick = new OnClickListener() {
public void onClick(View v) {
mrgText.setMargins(150, 100, 0, 0);
tvText.setLayoutParams(mrgText);
tvText.setText("Hy, i clicked the button!");
System.out.println(m_btn.getLayoutParams().height);
}
};
}
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks