SIMPLE TEXTVIEW
SOURCE CODE [main.xml] is
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
<TextView android:text="TextView"
</LinearLayout>
SOURCE CODE [TextViewExample.java] is
package com.TextViewExample;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class TextViewExample extends Activity
{
TextView tv;
public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView) findViewById(R.id.textView1);
tv.setText("Set Your Text to display here.");
}
}
The OUTPUT will be
SOURCE CODE [main.xml] is
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"><TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"android:text="@string/hello" />
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
SOURCE CODE [TextViewExample.java] is
package com.TextViewExample;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class TextViewExample extends Activity
{
TextView tv;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView) findViewById(R.id.textView1);
tv.setText("Set Your Text to display here.");
}
}
thanks man, learning my android now that I have a phone and needed just that info about TextView, on i plunge into the frisky waters of xml!
ReplyDeletecan you tell me have to show text after clicking on an item from a list.
ReplyDeleteI have a list of items in ListView.
What i want to do is:
After clicking on an item i want to show respective text in textView.
what i have done so far is:
listAdapter = new ArrayAdapter(this,R.layout.listView,R.id.textView,List);
public void onItemClick(AdapterView parent, View v,int position, long id)
{
System.out.println("position is:"+position);
switch (position)
{
case 0:
{
//text to show for case 0.
}
break;
case 1:
{
//text to show for case 1
}
break;
........
..........
........
thanks in advance.