what would be the best way to have an Android homescreen widget alternate between textviews?

I'm trying to create a homescreen Android widget and have it alternate between two different textviews I would send to it. Is this possible?

Answers


Why not maintain the same textview and just change the text shown?

If you really must use 2 text views you can use the setViewVisibility method in the RemoteViews object to alternate between GONE (which means not shown to user, takes up no screen space) and VISIBLE (shown to user, takes up screen space).


You could use a ViewFlipper to switch between multiple text views if that's what you meant.

 <ViewFlipper android:id="@+id/flipper"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:outAnimation="@anim/push_left_out"
                android:inAnimation="@anim/push_left_in">

                <TextView android:layout_height="fill_parent"
                    android:layout_width="fill_parent" android:padding="16dip"
                    android:id="@+id/txt1" android:textSize="8pt"
                    android:textColor="#ffffffff"
                    android:text="@string/text1"/>
                <TextView android:layout_height="fill_parent"
                    android:layout_width="fill_parent" android:padding="16dip"
                    android:id="@+id/txt1" android:textSize="8pt"
                    android:textColor="#ffffffff"
                    android:text="@string/text2"/>
</ViewFlipper>


ViewFlipper mFlipper = ((ViewFlipper) this.findViewById(R.id.flipper));

You could use a button event to switch between the text Views.

Button learn_more = (Button) findViewById(R.id.button);
        learn_more.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                mFlipper.showNext();

            }
        });

Hope it helps.


Need Your Help

Replacing double backslashes with single backslash

java string character-encoding replace backslash

I have a string "\\u003c", which belongs to UTF-8 charset. I am unable to decode it to unicode because of the presence of double backslashes. How do i get "\u003c" from "\\u003c"? I am using java.

Page redirect not working after loading content from SQL Database

php sql redirect header whitespace

I'm building an online commerce webpage. I have a 'check_inventory.php' page and I'm having an issue where after I query the page, I get all the data and all is good. But when I click a link to g...