2017-09-11 1 views
0

오늘 샘플 화면 제거를 다운로드하여 프로젝트에서 테스트하려고했지만 호환되지 않는 반환 값 유형에 문제가 있기 때문에 중지해야했습니다 ... https://developer.android.com/training/animation/screen-slide.html 그게 내가 다운로드 한 곳 그것.화면 슬라이드 용 ViewPager 사용 호환되지 않는 유형

ScreenSlideActivity :

package ur.mi.android.wgplus05.FotoApp; 
import android.support.v4.app.FragmentManager; 
import android.support.v4.app.Fragment; 
import android.content.Intent; 
import android.os.Bundle; 
import android.support.v4.app.FragmentActivity; 
import android.support.v4.app.FragmentStatePagerAdapter; 
import android.support.v4.app.NavUtils; 
import android.support.v4.view.PagerAdapter; 
import android.support.v4.view.ViewPager; 
import android.view.Menu; 
import android.view.MenuItem; 

import ur.mi.android.wgplus05.R; 

/** 
* Demonstrates a "screen-slide" animation using a {@link ViewPager}.   Because {@link ViewPager} 
* automatically plays such an animation when calling {@link 
ViewPager#setCurrentItem(int)}, there 
* isn't any animation-specific code in this sample. 
* 
* <p>This sample shows a "next" button that advances the user to the  

next step in a wizard, 
* animating the current screen out (to the left) and the next screen in  

(from the right). The 
* reverse animation is played when the user presses the "previous" 
button.</p> 
* 
* @see ScreenSlidePageFragment 
*/ 
public class ScreenSlideActivity extends FragmentActivity { 
/** 
* The number of pages (wizard steps) to show in this demo. 
*/ 
private static final int NUM_PAGES = 5; 

/** 
* The pager widget, which handles animation and allows swiping horizontally to access previous 
* and next wizard steps. 
*/ 
private ViewPager mPager; 

/** 
* The pager adapter, which provides the pages to the view pager widget. 
*/ 
private PagerAdapter mPagerAdapter; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_screen_slide); 

    // Instantiate a ViewPager and a PagerAdapter. 
    mPager = (ViewPager) findViewById(R.id.pager); 
    mPagerAdapter = new ScreenSlidePagerAdapter(getFragmentManager()); 

    **//ScreenSlidePagerAdapter 
    (android.support.v4.app.FragmentManager) 
    in ScreenSlidePagerAdapter cannot be applied 
    to android.app.FragmentManager)** 

    mPager.setAdapter(mPagerAdapter); 
    mPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { 
     @Override 
     public void onPageSelected(int position) { 
      // When changing pages, reset the action bar actions since they are dependent 
      // on which page is currently active. An alternative approach is to have each 
      // fragment expose actions itself (rather than the activity exposing actions), 
      // but for simplicity, the activity provides the actions in this sample. 
      invalidateOptionsMenu(); 
     } 
    }); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    super.onCreateOptionsMenu(menu); 
    getMenuInflater().inflate(R.menu.activity_screen_slide, menu); 

    menu.findItem(R.id.action_previous).setEnabled(mPager.getCurrentItem() > 0); 

    // Add either a "next" or "finish" button to the action bar, depending on which page 
    // is currently selected. 
    MenuItem item = menu.add(Menu.NONE, R.id.action_next, Menu.NONE, 
      (mPager.getCurrentItem() == mPagerAdapter.getCount() - 1) 
        ? R.string.action_finish 
        : R.string.action_next); 
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    switch (item.getItemId()) { 
     case android.R.id.home: 
      // Navigate "up" the demo structure to the launchpad activity. 
      // See http://developer.android.com/design/patterns/navigation.html for more. 
      NavUtils.navigateUpTo(this, new Intent(this, FotoWand.class)); 
      return true; 

     case R.id.action_previous: 
      // Go to the previous step in the wizard. If there is no previous step, 
      // setCurrentItem will do nothing. 
      mPager.setCurrentItem(mPager.getCurrentItem() - 1); 
      return true; 

     case R.id.action_next: 
      // Advance to the next step in the wizard. If there is no next step, setCurrentItem 
      // will do nothing. 
      mPager.setCurrentItem(mPager.getCurrentItem() + 1); 
      return true; 
    } 

    return super.onOptionsItemSelected(item); 
} 

/** 
* A simple pager adapter that represents 5 {@link CustomScreenSlidePageFragment} objects, in 
* sequence. 
*/ 
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { 
    public ScreenSlidePagerAdapter(FragmentManager fm) { 
     super(fm); 
    } 

    @Override 
    public Fragment getItem(int position) { 
     return ScreenSlidePageFragment.create(position); 
**// Incompatible types. 
Required: 
android.support.v4.app.Fragment 
Found: ur.mi.android.wgplus05.FotoApp.ScreenSlidePageFragment** 
    } 

    @Override 
    public int getCount() { 
     return NUM_PAGES; 
    } 
} 
} 

ScreenSliderPagerActivity :

package ur.mi.android.wgplus05.FotoApp; 

import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.support.v4.app.FragmentActivity; 
import android.support.v4.app.FragmentManager; 
import android.support.v4.app.FragmentStatePagerAdapter; 
import android.support.v4.view.PagerAdapter; 
import android.support.v4.view.ViewPager; 

import ur.mi.android.wgplus05.R; 

public class ScreenSlidePagerActivity extends FragmentActivity { 
/** 
* The number of pages (wizard steps) to show in this demo. 
*/ 
private static final int NUM_PAGES = 5; 

/** 
* The pager widget, which handles animation and allows swiping horizontally to access previous 
* and next wizard steps. 
*/ 
private ViewPager mPager; 

/** 
* The pager adapter, which provides the pages to the view pager widget. 
*/ 
private PagerAdapter mPagerAdapter; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_screen_slide); 

    // Instantiate a ViewPager and a PagerAdapter. 
    mPager = (ViewPager) findViewById(R.id.pager); 
    mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager()); 
    mPager.setAdapter(mPagerAdapter); 
} 

@Override 
public void onBackPressed() { 
    if (mPager.getCurrentItem() == 0) { 
     // If the user is currently looking at the first step, allow the system to handle the 
     // Back button. This calls finish() on this activity and pops the back stack. 
     super.onBackPressed(); 
    } else { 
     // Otherwise, select the previous step. 
     mPager.setCurrentItem(mPager.getCurrentItem() - 1); 
    } 
} 

/** 
* A simple pager adapter that represents 5 ScreenSlidePageFragment objects, in 
* sequence. 
*/ 
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { 
    public ScreenSlidePagerAdapter(FragmentManager fm) { 
     super(fm); 
    } 

    @Override 
    public Fragment getItem(int position) { 
     return new ScreenSlidePageFragment(); 
    ** // Incompatible types. 
    Required: 
    android.support.v4.app.Fragment 
    Found:ur.mi.android.wgplus05.FotoApp.ScreenSlidePageFragment** 
    } 

    @Override 
    public int getCount() { 
     return NUM_PAGES; 
    } 
} 
} 

내가 내가 함께 얻을 오류를 표시 ** 나는이 완전히 새로 온 사람이 모두 함께 작동하는 방법을 발견하지 않았습니다 . 누군가가 저를 도울 수 있기를 바랍니다! 미리 감사드립니다.

package ur.mi.android.wgplus05.FotoApp; 

import android.app.Fragment; 
import android.os.Bundle; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.TextView; 

import ur.mi.android.wgplus05.R; 

public class ScreenSlidePageFragment extends Fragment { 
/** 
* The argument key for the page number this fragment represents. 
*/ 
public static final String ARG_PAGE = "page"; 

/** 
* The fragment's page number, which is set to the argument value for {@link #ARG_PAGE}. 
*/ 
private int mPageNumber; 

/** 
* Factory method for this fragment class. Constructs a new fragment for the given page number. 
*/ 
public static ScreenSlidePageFragment create(int pageNumber) { 
    ScreenSlidePageFragment fragment = new ScreenSlidePageFragment(); 
    Bundle args = new Bundle(); 
    args.putInt(ARG_PAGE, pageNumber); 
    fragment.setArguments(args); 
    return fragment; 
} 

public ScreenSlidePageFragment() { 
} 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    mPageNumber = getArguments().getInt(ARG_PAGE); 
} 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    // Inflate the layout containing a title and body text. 
    ViewGroup rootView = (ViewGroup) inflater 
      .inflate(R.layout.fragment_screen_slide_page, container, false); 

    // Set the title view to show the page number. 
    ((TextView) rootView.findViewById(android.R.id.text1)).setText(
      getString(R.string.title_template_step, mPageNumber + 1)); 

    return rootView; 
} 

/** 
* Returns the page number represented by this fragment object. 
*/ 
public int getPageNumber() { 
    return mPageNumber; 
} 

}

+0

또한 ScreenSlidePageFragment 코드를 공유하시기 바랍니다 문제를 해결할 수 다음과 같은 사용자 정의 android.support.v4.app.Fragment

대신 ScreenSlidePageFragment에 대한 android.app.Fragment을 확장하고 –

+0

ScreenSlidePageFragment가 android.support.v4.app.Fragment를 확장하는지 확인합니다. –

답변

0

당신은 ScreenSlidePageFragment

public class ScreenSlidePageFragment extends android.support.v4.app.Fragment 

이것은

+0

괜찮 았지만 이제는 오류가 발생합니다. mPagerAdapter = new ScreenSlidePagerAdapter (getFragmentManager()); 그건 내가 v4에 적용 할 수 없다 .... fragmentmanager – boom3x

+0

뭐가 잘못 됐어? –

+0

이 mPagerAdapter 사용 = 새 ScreenSlidePagerAdapter (getSupportFragmentManager()); –