android: Can i use different class for different child of viewflipper

*爱你&永不变心* 提交于 2019-12-20 17:25:42

问题


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...


回答1:


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" />


来源:https://stackoverflow.com/questions/3994106/android-can-i-use-different-class-for-different-child-of-viewflipper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!