Кнопка скрывается при нажатии, и результаты отображаются в студии android - PullRequest
0 голосов
/ 12 июля 2020

Я пытаюсь создать приложение, которое может отображать вывод команд оболочки. Это выглядит так: https://i.stack.imgur.com/B6web.png

Когда я нажимаю кнопку ping с какой-либо командой оболочки в качестве ввода, например (ls / pro c), вывод команды перезаписывает кнопку ping. (т.е. кнопка ping становится невидимой)

Main xml

<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();
                }
            }
        });
    }
}

1 Ответ

0 голосов
/ 12 июля 2020

Если вы хотите скрыть btn_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);
                    //here is where you hide the button
                    btn_ping.setVisibility(View.GONE);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
...