Sunday, January 1, 2012

android : visible invisible textView by click in button

1- get the reference for the textView
      open /res/layout/main.xml and add in the textView
android:id="@+id/haikuTextView"
        in button method
public void buttonName (View view) {
TextView textView=(TextView) findViewById(R.id.haikuTextView);//1
 textView.setVisibility(View.VISIBLE); //2
}
1 - click create field in R.id

Android : Button

 in /res/layout/main.xml.
add below

<Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/name"
        android:onClick="buttonName" />

android:text ->  change text inside the button
open res/values/strings.xml
add this : 
 <string name="name>some text here</string>

android:onClick - > add event when button is click ( android 1.6 above)
to add the event -> open java file in src
add this as method name in the class
public void buttonName (View view) {
 // add some action

need to import android.view.View
method name = = value in android:onClick

Android : Text View Widget

in main.xml
<TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello"
        android:visibility="invisible"
      />
edit the android:text
open res/values/strings.xml
add this : 
 <string name="hello">some text here</string>
android:visibility 
ConstantValueDescription
visible0 Visible on screen; the default value.
invisible1 Not displayed, but taken into account during layout (space is left for it).
gone2 Completely hidden, as if the view had not been added.