2015-06-12 174 views
0

我尝试创建一个TabLayout活动的支持设计,但我有此错误:材料设计TabLayout

Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/design/R$styleable;

这是我的代码:

public class GetListeModelActivity extends FragmentActivity { 


SectionsPagerAdapter mSectionsPagerAdapter; 
public int RESULT_EDIT_LISTEMODEL=1; 

ViewPager mViewPager; 
List<Fragment> fragments; 

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

    final ActionBar actionBar = getActionBar(); 
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME|ActionBar.DISPLAY_SHOW_TITLE|ActionBar.DISPLAY_SHOW_CUSTOM|ActionBar.DISPLAY_HOME_AS_UP); 

    // Create the adapter that will return a fragment for each of the three 
    // primary sections of the activity. 
    fragments= new Vector<Fragment>(); 

    Bundle b0; 
    //Bundle b1 = savedInstanceState; 
    //savedInstanceState.putInt("typeliste", 1); 
    if(savedInstanceState==null) 
    { 
     b0=new Bundle(); 
    } 
    else 
    { 
    b0= savedInstanceState; 
    // b1 = savedInstanceState; 
    } 
    b0.putInt("typelistemodel", 0); //Your id//Put your id to your next Intent 

    fragments.add(Fragment.instantiate(this,ListeModelFragment.class.getName(),b0)); 

    b0.putInt("typelistemodel", 1); 
    fragments.add(Fragment.instantiate(this,ListeModelFragment.class.getName(),b0)); 

    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager(), fragments); 


    // Set up the ViewPager with the sections adapter. 
    mViewPager = (ViewPager) findViewById(R.id.pager); 
    mViewPager.setAdapter(mSectionsPagerAdapter); 


    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); 
    tabLayout.setupWithViewPager(mViewPager); 


} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.get_liste_model, menu); 
    return true; 
} 

@Override 
public boolean onPrepareOptionsMenu(Menu menu) { 
     // TODO Auto-generated method stub 
     MenuInflater inflater = getMenuInflater(); 
     menu.clear(); 
     switch (mViewPager.getCurrentItem()) 
     { 
     case 0 : 
      inflater.inflate(R.menu.get_liste_model, menu); 
      break; 
     case 1 : 
      inflater.inflate(R.menu.get_liste_model1, menu); 
      break; 
     } 

     return super.onPrepareOptionsMenu(menu); 
    } 

@Override 
public boolean onMenuItemSelected(int featureId, MenuItem item) { 

    int itemId = item.getItemId(); 
    switch (itemId) { 
    case android.R.id.home: 

     onBackPressed(); 
     //do your action here. 
     break; 
    case R.id.action_add: 

     Intent intent = new Intent(this, EditListeModelActivity.class); 
     Bundle b = new Bundle(); 
     b.putInt("typelistemodel", 0); //Your id 
     intent.putExtras(b); //Put your id to your next Intent 
     startActivityForResult(intent, RESULT_EDIT_LISTEMODEL); 
     break; 


    case R.id.action_add1: 

     Intent intent1 = new Intent(this, EditListeModelActivity.class); 
     Bundle b1 = new Bundle(); 
     b1.putInt("typelistemodel", 1); //Your id 
     intent1.putExtras(b1); //Put your id to your next Intent  
    startActivityForResult(intent1, RESULT_EDIT_LISTEMODEL); 
     break; 

    } 

    return super.onOptionsItemSelected(item); 
} 


@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 
    if (id == R.id.action_settings) { 
     return true; 
    } 
    return super.onOptionsItemSelected(item); 
} 

    /** 
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to 
* one of the sections/tabs/pages. 
*/ 
public class SectionsPagerAdapter extends FragmentPagerAdapter { 

    private final List<Fragment> fragments; 


    public SectionsPagerAdapter(FragmentManager fm, List<Fragment> fragments) { 
     super(fm); 
     this.fragments = fragments; 
     // TODO Auto-generated constructor stub 
    } 


    @Override 
    public Fragment getItem(int position) { 
     // getItem is called to instantiate the fragment for the given page. 
     // Return a PlaceholderFragment (defined as a static inner class 
     // below). 
     //return PlaceholderFragment.newInstance(position + 1); 
     return this.fragments.get(position); 
    } 

    @Override 
    public int getCount() { 
     // Show 3 total pages. 
     return this.fragments.size(); 
    } 

    @Override 
    public CharSequence getPageTitle(int position) { 
     Locale l = Locale.getDefault(); 
     switch (position) { 
     case 0: 
      return getString(R.string.title_section1).toUpperCase(l); 
     case 1: 
      return getString(R.string.title_section2).toUpperCase(l); 
     case 2: 
      return getString(R.string.title_section3).toUpperCase(l); 
     } 
     return null; 
    } 
} 

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 


    if (requestCode == RESULT_EDIT_LISTEMODEL && resultCode==1) { 
     if(MyUser.mesListesModeles.size()>0) 
     { 
      for (Fragment fragment : fragments) { 
       fragment.onActivityResult(requestCode, resultCode, data); 
      } 

     } 
    } 
} 

}

我的布局:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/pager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

</LinearLayout> 

Can 你帮我?

+0

它抱怨找不到类的定义,请检查您是否有' \t com.google.android \t 支持-V4在你的pom.xml \t R6 ' – Arpit

回答

0
  1. 确保您正确,包括设计库为每instructions(这是更相关的,如果你使用的是Eclipse,而不是摇篮/ Android的工作室)。

  2. 设计库取决于AppCompat - 如果您使用的是设计库,请确保您使用AppCompatActivityTheme.AppCompat-这是设计库如何获得其样式和主题。