+ 4

How can i declare onclick?

25th Mar 2017, 2:01 PM
Prabhakar Dev
Prabhakar Dev - avatar
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
25th Mar 2017, 2:13 PM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 7
Btw use that @Abdul Moqueet's code instead I can't android with java
25th Mar 2017, 2:22 PM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 6
import java.awt.event.MouseAdapter; (That variable of button).addMouseMotionListener(new MouseAdapter(){ public void mouseClicked(){ //function you want } });
25th Mar 2017, 2:07 PM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 6
But Android studio is only for Windows, Mac OS, and Linux. I want something on Android
25th Mar 2017, 3:21 PM
Prabhakar Dev
Prabhakar Dev - avatar
+ 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
25th Mar 2017, 3:24 PM
Prabhakar Dev
Prabhakar Dev - avatar
+ 5
Do anyone of you all know about a good android ide for Android platform? If you do please tell
25th Mar 2017, 2:34 PM
Prabhakar Dev
Prabhakar Dev - avatar
+ 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 '}' }
26th Mar 2017, 4:02 PM
Prabhakar Dev
Prabhakar Dev - avatar
+ 4
Is that all I thoughts that the would be done different functions in android
25th Mar 2017, 2:11 PM
Prabhakar Dev
Prabhakar Dev - avatar
+ 4
Would gridview also work?
25th Mar 2017, 2:12 PM
Prabhakar Dev
Prabhakar Dev - avatar
+ 4
It's not working
25th Mar 2017, 2:14 PM
Prabhakar Dev
Prabhakar Dev - avatar
+ 1
Go to XML and add an attribute android:onClick = method name here
26th Mar 2017, 11:33 AM
AbdulSammad
AbdulSammad - avatar