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