Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] Button Gets Hidden when clicked and results are shown in android studio

Posted on November 14, 2022

Solution 1 :

If you want to hide the btn_ping after a click, try setting visibility gone like this

btn_ping.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    String cmd = et_ip.getText().toString();
                    PingIp.executecmd(cmd, tv_result);
                    //here is where you hide the button
                    btn_ping.setVisibility(View.GONE);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

Problem :

I am trying to create an application that can show output of shell commands. It looks like this
https://i.stack.imgur.com/B6web.png

When i click the ping Button with some shell command as input eg(ls /proc) the output of the command overwrites the ping button.(i.e the ping button becomes invisible)

Mainxml

<LinearLayout xmlns_android="http://schemas.android.com/apk/res/android"
    android_layout_width="match_parent"
    android_layout_height="wrap_content"
    xmlns_tools="http://schemas.android.com/tools"
    tools_context=".MainActivity"
    android_orientation="vertical">


        <EditText
            android_id="@+id/edittext_ip"
            android_layout_width="match_parent"
            android_layout_height="wrap_content"
            android_layout_marginTop="10dp"
            android_inputType="textPersonName"
            android_hint="Enter ip"
            tools_ignore="HardcodedText"
            android_autofillHints="None" />

        <Button
            android_id="@+id/button_ping"
            android_layout_width="match_parent"
            android_layout_height="0dp"
            android_layout_marginTop="10dp"
            android_layout_marginBottom="10dp"
            android_layout_weight="1"
            android_text="Ping"
            tools_ignore="HardcodedText" />

        <ScrollView
            android_layout_width="match_parent"
            android_layout_height="wrap_content"
            android_layout_marginTop="10dp"
            android_layout_marginBottom="10dp"
            android_scrollbars="vertical"
            android_fillViewport="true"
            android_id="@+id/scrollview_pingresult"
            tools_ignore="ExtraText">

            <LinearLayout
                android_layout_width="match_parent"
                android_layout_height="wrap_content">
                <TextView
                    android_id="@+id/textview_pingresult"
                    android_layout_width="match_parent"
                    android_layout_height="wrap_content"
                    />
            </LinearLayout>

        </ScrollView>
    </LinearLayout>

MainActivity.java

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final TextView tv_result = findViewById(R.id.textview_pingresult);
        final EditText et_ip = findViewById(R.id.edittext_ip);
        final Button btn_ping = findViewById(R.id.button_ping);


        btn_ping.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    String cmd = et_ip.getText().toString();
                    PingIp.executecmd(cmd, tv_result);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
}
READ  [ANSWERED] android - Bitrise: Could not resolve all artifacts for configuration ':classpath' Could not resolve com.google.gms:google-services:4.2.0
Powered by Inline Related Posts

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress