Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid button having two functions
    primarykey
    data
    text
    <p>I need to have a button that is suppose to have two functions.</p> <p>If I tap on it once, it will go to the next page. If I hold down on the button, it will allow me to edit the text on the button.</p> <p>The button is able to go to the next page upon tapping on it, but how do I implement the second function which allows me to change the text If I hold down the button?</p> <p>Does anybody know?</p> <p>java code</p> <pre><code>public class MainActivity extends Activity { Button button1; Button button2; Button button3; Handler h; private Socket socket; private boolean mInSettingsMode; private static final int SERVERPORT = 5000; private static final String SERVER_IP = "192.168.43.83"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); new Thread(new ClientThread()).start(); // living button click start button1 = (Button) findViewById(R.id.btnliving); button1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub h = new Handler(); h.postDelayed(irun, 0); } }); button2 = (Button) findViewById(R.id.btnbed); button2.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub h = new Handler(); h.postDelayed(irun2, 0); } }); button3 = (Button) findViewById(R.id.btndin); button3.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub h = new Handler(); h.postDelayed(irun3, 0); } }); } Runnable irun = new Runnable() { @Override public void run() { // TODO Auto-generated method stub Intent i = new Intent(MainActivity.this, living.class); startActivity(i); finish(); overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); } }; Runnable irun2 = new Runnable() { @Override public void run() { // TODO Auto-generated method stub Intent i = new Intent(MainActivity.this, bed.class); startActivity(i); finish(); overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); } }; Runnable irun3 = new Runnable() { @Override public void run() { // TODO Auto-generated method stub Intent i = new Intent(MainActivity.this, din.class); startActivity(i); finish(); overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); } }; /* * @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the * menu; this adds items to the action bar if it is present. * getMenuInflater().inflate(R.menu.main, menu); return true; } */ class ClientThread implements Runnable { @Override public void run() { try { InetAddress serverAddr = InetAddress.getByName(SERVER_IP); // new Thread(new ClientThread()).start(); socket = new Socket(serverAddr, SERVERPORT); } catch (UnknownHostException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } } } } </code></pre> <p>xml code </p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:gravity="center" android:orientation="vertical" android:background="@drawable/back1" tools:context=".MainActivity" &gt; &lt;Button android:id="@+id/btnliving" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Light Control" /&gt; &lt;Button android:id="@+id/btnbed" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Fan Control" /&gt; &lt;Button android:id="@+id/btndin" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Thermostat Control" /&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload