2

i new to the android programming. I've tried to create a IRC bot. I've used the Pircbot libraries. My app can connect to the server but i can't understand how to show the chat's output in the android's textview. Can you help me? Pircbot print it in the Android Logcat, are there a way to print Logcat in a textView? Thank You so much

This is my starting_bot.java:

import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

public class starting_bot extends MainActivity {
private irc_connection mAuthTask = null;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mAuthTask = new irc_connection();
    mAuthTask.execute((Void) null);
    setContentView(R.layout.started_bot);

}


public class irc_connection  extends AsyncTask<Void, Void, Boolean> {
    @Override
    protected void onPreExecute(){
    }

    @Override
    protected void onProgressUpdate(Void[] values) {

    };

    @Override
    protected Boolean doInBackground(Void... params) {

        //ESEGUIRE OPERAZIONI IN BACKGROUND
        BotClass bot = new BotClass("nickname123");
        try {
            bot.setVerbose(true);
            bot.connect("irc server");
            //bot.sendMessage("nickserv","IDENTIFY <your password>" );
            bot.joinChannel("#ircchannel");
            Log.d("BOT:", "CONNESSO!");

        } catch (Exception e) {
            e.printStackTrace();
        }

        return true;


    }

    @Override
    protected void onPostExecute(final Boolean success) {

    }

    @Override
    protected void onCancelled() {
        mAuthTask = null;
    }
}

that is my output page:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<View
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/output_java"/>
</LinearLayout>
Gio Picca
  • 21
  • 2
  • Couple of issues, first to print anything to a TextView you will need to use findViewById method to get a handle to the TextView which is on the screen. – Daniel Mendel Jan 09 '16 at 18:47
  • Second you use an AsynTask which does stuff in another thread, which is fine, but you can't update the text of the TextView from within the other thread, all UI actions need to take placeon the UI Thread which is the main thread your applican runs in, – Daniel Mendel Jan 09 '16 at 18:48
  • To avoid it you will need to call updateProgress from within the doInBackground method, that updateProgress method runs on the UI Thread, you will need to send the data from the do in background method to the updateProgress method, and update that textview from the updateProgress Method – Daniel Mendel Jan 09 '16 at 18:49
  • Thank you very much for your answer. but i can't understant how to pass the data from the irc connection to the textview. can you make some example? Thank you much for your time – Gio Picca Jan 09 '16 at 18:57

0 Answers0