views:

54

answers:

2

Hi, I have different screen to work in an android application. I'm using ViewFlipper for this. I decided to used different class for different view children

public main extends Activity{
{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sign_in);
    ViewFlipper viewFlipper = (ViewFlipper) findViewById(R.id.viewFlipper);

HomeScreen s = new HomeScreen(getApplicationContext(), getCurrentFocus(), viewFlipper);
  }
} 

and this the Homescreen class is :-

public class HomeScreen {
private Button signIn;
private Button createAccount;
private View v;
private Context context;
private ViewFlipper viewflipper;

public HomeScreen(Context context,View v,ViewFlipper viewflipper ) {
 this.v=v;
 this.context = context;
 this.viewflipper = viewflipper;


 signIn = (Button) v.findViewById(R.id.button_sign_in_homeScreen);
 createAccount = (Button)v.findViewById(R.id.button_createAccount_homeScreen);
 signIn.setOnClickListener(new View.OnClickListener() {
 public void onClick(View v) {
   viewflipper.setDisplayedChild(1);
  }
 });   
}

but is shows run exception java.lang.RuntimeException: Unable to start activity ComponentInfo Can anyone please help me
is getCurrentFocus() is the correct way to get the view?


What i try to implement is

  • I need to use different class for defining, listening the controls of each child of view flipper
  • In the above example HomeScreen is one of my the child screen of view flipper
  • But the line v.findViewById is showing error i think that getCurrentFocus() is not the correct way to sent the view

I don't know weather i'm moving in the correct way? When i define and listen all the controls of all children of viewflipper in the Class where i define that viewflpper, that class become very big. That made me to think so..

Thanks...

A: 

Hai Labeeb Brother, Pls go through this url, it has a sample which shows how viewflipper is implemented. http://www.codeshogun.com/blog/tag/view-flipper/

Labbeb Brother, pls go through this url also http://www.warriorpoint.com/blog/2009/05/26/android-switching-screens-in-an-activity-with-animations-using-viewflipper/

Tilsan The Fighter
Actually no problem in implementing viewflipper, But i tried to define and listen the controls in different class...Thanks
Labeeb P
+1  A: 

U can perfrom animation using Intent to:

Step1: create anim folder under res directory in ur project.

Step2: create an slideleft.xml file

Step3: type the following code in that file

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_interpolator">
    <translate android:fromXDelta="100%p" android:toXDelta="0"
        android:duration="400" />
</set>

step 4: similarly create slideright.xml

step5: use the above code, but change the following

<translate android:fromXDelta="-100%p" android:toXDelta="0"
            android:duration="400" />

step 6:

 target.startAnimation(AnimationUtils.loadAnimation(HomeScreen.this, R.anim.slide_left));

perfroming fadein operation, just add the following code in fadein.xml file

<?xml version="1.0" encoding="utf-8"?>

<alpha xmlns:android="http://schemas.android.com/apk/res/android"
       android:interpolator="@android:anim/accelerate_interpolator"
       android:fromAlpha="0.0" android:toAlpha="1.0"
       android:duration="300" />

similarly for fade out too

<?xml version="1.0" encoding="UTF-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
       android:interpolator="@android:anim/accelerate_interpolator"
       android:fromAlpha="1.0" android:toAlpha="0.0"
       android:duration="300" />
Tilsan The Fighter
OK..thanks ...it new information for me..............
Labeeb P