+ 4
How can i declare onclick?
11 Respuestas
+ 7
Not sure.....because I can't install android studio to test.....
But I bet It's can!
Because of this function can add to all Object
+ 7
Btw use that @Abdul Moqueet's code instead
I can't android with java
+ 6
import java.awt.event.MouseAdapter;
(That variable of button).addMouseMotionListener(new MouseAdapter(){
public void mouseClicked(){
//function you want
}
});
+ 6
But Android studio is only for Windows, Mac OS, and Linux.
I want something on Android
+ 6
Is there any error?
package com.mycompany.myappp;
import android.widget.*;
import android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
public class MainActivity extends Activity{
TextView t=(TextView)findViewById(R.id.mainTextView);
Button b=(Button)findViewById(R.id.mainButton);
View.OnClickListener e=new View.OnClickListener() {
public void onClick(View v) {
t.setText("Hi bro!");
}
};
@Override
protected void onCreate(Bundle savedInstanceState)
{
b.setOnClickListener(e);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
The app gets compiled but doesn't open
+ 5
Do anyone of you all know about a good android ide for Android platform?
If you do please tell
+ 5
@AbdulSammad
Is there something wrong here? My ide is pointing out some errors that I think it shouldn't
main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:text="Yo!"
android:id="@+id/mainTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/mainButton"
android:text="Change"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:onClick="change"
/>
</LinearLayout>
Main activity.java:
package com.mycompany.myapp2l;
import android.app.*;
import android.os.*;
import android.widget.*;
import android.view.View;
/*
*@author:Prabhakar
*/
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView t=(TextView)findViewById(R.id.mainTextView);
Button b=(Button)findViewById(R.id.mainButton);//Hre it says missing '}'
public void change(View v){
t.setText("Hello");//Here it says unknown entity 't'
}
}//Here it says unexpected '}'
}
+ 4
Is that all I thoughts that the would be done different functions in android
+ 4
Would gridview also work?
+ 4
It's not working
+ 1
Go to XML and add an attribute android:onClick = method name here