Um unsere Webseite für Sie optimal zu gestalten und fortlaufend verbessern zu können, verwenden wir Cookies. Durch die weitere Nutzung der Webseite stimmen Sie der Verwendung von Cookies zu. Diese Seite zeigt lediglich nicht-personalisierte Werbung an, um der neuen EU-Datenschutzgrundverordnung gerecht zu werden.
Translate
Sonntag, 20. März 2016
Android-Java-AsyncTask Beispiel
package com.sshapp.tim.sshservershutdownandrestart; import android.os.AsyncTask; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.Button; import android.widget.ScrollView; import android.widget.TextView; import com.jcraft.jsch.ChannelExec; import com.jcraft.jsch.JSch; import com.jcraft.jsch.Session; import java.text.DateFormat; import java.util.Date; import java.util.Properties; public class Main extends AppCompatActivity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setTitle("MyApp"); Button mybutton1 = (Button)
findViewById(R.id.mybutton1);
Button mybutton2 = (Button)
findViewById(R.id.mybutton2); //Set click events mybutton1.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View view) { onRestartClick((Button) view); } }); mybutton12.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View view) { onShutdownClick((Button) view); } }); } private void onRestartClick(Button view) { new AsyncSSHTask().execute("param1"); } private void onShutdownClick(Button view) { new AsyncSSHTask().execute("param1"); } private void ScrollViewDown(){ ScrollView scrollViewLogging = (ScrollView)
findViewById(R.id.scrollViewScroll); scrollViewLogging.post(new Runnable() { public void run() { ScrollView scrollViewLogging = (ScrollView)
findViewById(R.id.scrollViewScroll); scrollViewLogging.fullScroll(View.FOCUS_DOWN); } }); } private void Log(String text){ TextView textViewLogging = (TextView)
findViewById(R.id.textViewLogging); String currentDateTimeString = DateFormat.
getDateTimeInstance().format(new Date()); textViewLogging.append(currentDateTimeString + ": "
+ text + "\n"); ScrollViewDown(); } public void LogPublic(String text) { final String str = text; Main.this.runOnUiThread(new Runnable() { @Override public void run() { Log(str); } }); } public class MyAsyncTask extends AsyncTask<String, Integer,
Long> { @Override protected Long doInBackground(String... params) { try {
//Your code here return new Long(1); } catch (Exception ex) { LogPublic(ex.getMessage()); return new Long(0); } } } }
Android-Java-ScrollView nach ganz unten scrollen
ScrollView mScrollView= (ScrollView) findViewById(R.id.mScrollView);
mScrollView.post(new Runnable() { public void run() { mScrollView.fullScroll(View.FOCUS_DOWN); } });
Android-Java-Toolbar ohne Settings
@Overridepublic boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present. //getMenuInflater().inflate(R.menu.menu_main, menu); return true;
}
entfernen --> Settings (3 Punkte sind weg)
Abonnieren
Posts (Atom)