PDA

View Full Version : how to print message on console



poojs
07-17-2009, 03:11 AM
hello
i am new to android.
can any1 tellme how can we display message on android's console...like we print msg in j2me by System.out.println
what we use for android as System.out is not works on android.
and how can we handle events in android.

dre_b
07-25-2009, 04:34 PM
to post text on the screen you can make a text view and then call setText("").

for events, you need to add an event handler. lets use a button for example:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<Button android:id="@+id/Button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="clickme"
/>
</LinearLayout>



public class yourApp extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button Button1 = (Button) findViewById(R.id.Button1);
Button1.setOnClickListener(button1ClickEvent);
}

// Button events
private OnClickListener button1ClickEvent = new OnClickListener()
{
public void onClick(View v)
{
// handle click
}
};
}

cricaddict
06-29-2010, 12:37 PM
@dre_b
the given code is not printing anything on console of eclipse....
its for printing any stuff on UI of android phone........
dats d basic code n a very common android app code...

some1 post some real code for writing anything on console as it hepls in debuggin d code very easily...
u cant configure eveythng frm UI to .java file.......