problem with setText at EditText

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

problem with setText at EditText

Postby georpapa » Tue Oct 06, 2009 7:30 pm

hello, i am new here, but i was watching the posts as i am a developer, buti am still newbie in Android

I want to make an application for simple chat, but i have problem making the chat-log to work
the problem specific is that when i have an icoming message i want this text to be shown in the input (EditText)

but when i write the code
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. input.setText(inmessage);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4

in the middle of the conn "subprogramm" the programma soes never show that message in the field and on the other hand the programma dows not work properly, the code

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. out.println("Echo :"+inmessage);
  2.  
  3. if(inmessage.equals("BYE"))done=true;
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


is like that there is not exist..
what is the problem?
ty in advance

here is the code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.android.maptest;
  2.  
  3.  
  4.  
  5. import android.app.Activity;
  6.  
  7. import android.os.Bundle;
  8.  
  9. import android.view.View;
  10.  
  11. import android.widget.Button;
  12.  
  13. import android.widget.EditText;
  14.  
  15. import java.net.ServerSocket;
  16.  
  17. import java.net.Socket;
  18.  
  19. import java.io.BufferedReader;
  20.  
  21. import java.io.InputStreamReader;
  22.  
  23. import java.io.PrintWriter;
  24.  
  25.  
  26.  
  27. public class chatting extends Activity {
  28.  
  29.         public EditText input;
  30.  
  31.     private EditText output;
  32.  
  33.     BufferedReader in;
  34.  
  35.     PrintWriter out;
  36.  
  37.     String inputmessage="empty...";
  38.  
  39.     String inmessage;
  40.  
  41.     int i=1;
  42.  
  43.     protected void onCreate(Bundle savedInstanceState) {
  44.  
  45.                 // TODO Auto-generated method stub
  46.  
  47.                 super.onCreate(savedInstanceState);
  48.  
  49.                 setContentView(R.layout.chatting);
  50.  
  51.                 new Comm().start();
  52.  
  53.                
  54.  
  55.                 input= (EditText) findViewById(R.id.inputchat);
  56.  
  57.                 input.setText(" ");
  58.  
  59.                 output= (EditText) findViewById(R.id.outputchat);
  60.  
  61.                 output.setText(" ");
  62.  
  63.                 Button sendbutton = (Button) findViewById(R.id.sendbutton);
  64.  
  65.                 sendbutton.setOnClickListener(new View.OnClickListener() {
  66.  
  67.  
  68.  
  69.                     public void onClick(View view) {
  70.  
  71.                         out.println(output.getText());
  72.  
  73.                          
  74.  
  75.     }
  76.  
  77.                 });
  78.  
  79.                
  80.  
  81.                        
  82.  
  83.                
  84.  
  85.                
  86.  
  87.    
  88.  
  89.    
  90.  
  91.    
  92.  
  93.     }
  94.  
  95.    
  96.  
  97.    
  98.  
  99.     public class Comm extends Thread
  100.  
  101.         {                      
  102.  
  103.                 public void run()                      
  104.  
  105.                 {              
  106.  
  107.                         try
  108.  
  109.                      { // establish server socket
  110.  
  111.                                
  112.  
  113.                                
  114.  
  115.                         ServerSocket s = new ServerSocket(8188);
  116.  
  117.                         // wait for client connection – as soon as this comes,
  118.  
  119.                          Socket incoming = s.accept ( ); //socket obj. incoming is constructed  
  120.  
  121.                          in = new BufferedReader (new InputStreamReader(incoming.getInputStream()));
  122.  
  123.                          out = new PrintWriter (incoming.getOutputStream(),true/* autoFlush */);
  124.  
  125.                          out.println( "Start talking..." );
  126.  
  127.                          out.println("ola kala?");
  128.  
  129.                        
  130.  
  131.                         Boolean done=false;
  132.  
  133.                          while(!done)
  134.  
  135.                          {Thread.sleep(1000);
  136.  
  137.                                  if(in.ready()){
  138.  
  139.                                                
  140.  
  141.                                                 inmessage=in.readLine();
  142.  
  143.                                                 inputmessage=inmessage;
  144.  
  145.                                                 out.println("Echo :"+inmessage);
  146.  
  147.                                                 if(inmessage.equals("BYE"))done=true;
  148.  
  149.                                          input.setText(inmessage);
  150.  
  151.                                          
  152.  
  153.                                                
  154.  
  155.                                          }
  156.  
  157.                          }out.println("End discussion...");
  158.  
  159.                          incoming.close();
  160.  
  161.    
  162.  
  163.                      }catch (Exception e) { e.printStackTrace(); }
  164.  
  165.    
  166.  
  167. }}
  168.  
  169.    
  170.  
  171.     void fillinput(String in){
  172.  
  173.         input.setText(in);
  174.  
  175.     }
  176.  
  177.  
  178.  
  179.  
  180.  
  181. }
  182.  
  183.  
Parsed in 0.044 seconds, using GeSHi 1.0.8.4


and here the xml
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="UTF-8"?>
  3.  
  4. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.         android:orientation="vertical" android:layout_width="fill_parent"
  7.  
  8.         android:layout_height="fill_parent">
  9.  
  10.  
  11.  
  12.         <EditText android:id="@+id/inputchat"
  13.  
  14.         android:layout_width="wrap_content"
  15.  
  16.         android:layout_height="wrap_content"
  17.  
  18.         android:editable="true" android:visibility="visible">
  19.  
  20.         </EditText>
  21.  
  22.         <EditText android:id="@+id/outputchat"
  23.  
  24.         android:layout_width="wrap_content"
  25.  
  26.         android:layout_height="wrap_content"
  27.  
  28.         android:editable="true" android:text="arxi" android:visibility="visible">
  29.  
  30.         </EditText>
  31.  
  32.         <Button android:id="@+id/sendbutton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="send"></Button>
  33.  
  34. </LinearLayout>
Parsed in 0.003 seconds, using GeSHi 1.0.8.4
georpapa
Freshman
Freshman
 
Posts: 9
Joined: Tue Oct 06, 2009 7:22 pm

Top

Postby Emmanuel7 » Wed Oct 07, 2009 12:10 am

Only the main thread can modify the UI !

If you want to do that somewhere, use messages, or the runOnUiThread method.
Emmanuel7
Senior Developer
Senior Developer
 
Posts: 164
Joined: Fri Dec 12, 2008 2:17 am
Location: Paris

Postby georpapa » Wed Oct 07, 2009 11:36 am

ty very much

it worked properly :)
georpapa
Freshman
Freshman
 
Posts: 9
Joined: Tue Oct 06, 2009 7:22 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 3 guests