#java #android
Уже 3 дня мучаюсь... Я создавал табы отдельно и recyclerView отдельно, теперь обьединил. Запускаю не запускается Unfortunately!!! В чем может быть проблема? MainActivity: public class MainActivity extends AppCompatActivity { private Toolbar toolbar; private TabLayout tabLayout; private ViewPager viewPager; private int[] tabIcons = { R.drawable.ic_action_person, R.drawable.ic_action_group, R.drawable.ic_action_call }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); viewPager = (ViewPager) findViewById(R.id.viewpager); setupViewPager(viewPager); tabLayout = (TabLayout) findViewById(R.id.tablayout); tabLayout.setupWithViewPager(viewPager); } private void setupViewPager(ViewPager viewPager) { ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager()); adapter.addFragment(new TabOneFragment(), "One"); adapter.addFragment(new TabTwoFragment(), "Two"); adapter.addFragment(new TabThreeFragment(), "Three"); viewPager.setAdapter(adapter); } } TabOneFragment: public class TabOneFragment extends Fragment { private RecyclerView recyclerview; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.tab_one_fragment, container, false); recyclerview = (RecyclerView)view.findViewById(R.id.recyclerview); LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity()); recyclerview.setLayoutManager(layoutManager); return view; } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ArrayListitems = new ArrayList<>(); RVAdapter adapter = new RVAdapter(items); recyclerview.setAdapter(adapter); } } RVAdapter: public class RVAdapter extends RecyclerView.Adapter { private List mItems; public RVAdapter(List mItems) { this.mItems = mItems; } public class ItemViewHolder extends RecyclerView.ViewHolder { TextView departCode; TextView departTime; TextView departDate; TextView arriveCode; TextView arriveTime; TextView arriveDate; TextView flyTime; Button ticketPrice; ImageView airlineLogo; public ItemViewHolder(View itemView) { super(itemView); departCode = (TextView) itemView.findViewById(R.id.tvAirCodeDepart); departTime = (TextView) itemView.findViewById(R.id.tvDepartTime); departDate = (TextView) itemView.findViewById(R.id.tvDepartDate); arriveCode = (TextView) itemView.findViewById(R.id.tvCodeArrive); arriveTime = (TextView) itemView.findViewById(R.id.tvArriveTime); arriveDate = (TextView) itemView.findViewById(R.id.tvArriveDate); flyTime = (TextView) itemView.findViewById(R.id.tvTime); ticketPrice = (Button) itemView.findViewById(R.id.btnTickPrice); airlineLogo = (ImageView) itemView.findViewById(R.id.ivAirlineLogo); } } @Override public void onBindViewHolder(ItemViewHolder itemViewHolder, int i) { itemViewHolder.departCode.setText(mItems.get(i).getDepartCode()); itemViewHolder.departTime.setText(mItems.get(i).getDepartTime()); itemViewHolder.departDate.setText(mItems.get(i).getDepartDate()); itemViewHolder.arriveCode.setText(mItems.get(i).getArriveCode()); itemViewHolder.arriveTime.setText(mItems.get(i).getArriveTime()); itemViewHolder.arriveDate.setText(mItems.get(i).getArriveDate()); itemViewHolder.flyTime.setText(mItems.get(i).getFlyTime()); itemViewHolder.ticketPrice.setText(mItems.get(i).getTicketPrice()); itemViewHolder.airlineLogo.setImageResource(mItems.get(i).getAirlineLogo()); } @Override public ItemViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_row, viewGroup, false); return new ItemViewHolder(view); } @Override public int getItemCount() { return mItems.size(); } } TicketsObjects public class TicketObjects { private String departCode; private String departTime; private String departDate; private String arriveCode; private String arriveTime; private String arriveDate; private String flyTime; private String ticketPrice; private int airlineLogo; public TicketObjects(String departCode, String departTime, String departDate, String arriveCode, String arriveTime, String arriveDate, String flyTime, String ticketPrice, int airlineLogo) { this.departCode = departCode; this.departTime = departTime; this.departDate = departDate; this.arriveCode = arriveCode; this.arriveTime = arriveTime; this.arriveDate = arriveDate; this.flyTime = flyTime; this.ticketPrice = ticketPrice; this.airlineLogo = airlineLogo; } public String getDepartCode(){ return departCode; } public void setDepartCode(String departCode){ this.departCode = departCode; } public String getDepartTime(){ return departTime; } public void setDepartTime(String departTime){ this.departTime = departTime; } public String getDepartDate(){ return departDate; } public void setDepartDate(String departDate){ this.departDate = departDate; } public String getArriveCode(){ return arriveCode; } public void setArriveCode(String arriveCode){ this.arriveCode = arriveCode; } public String getArriveTime(){ return arriveTime; } public void setArriveTime(String arriveTime){ this.arriveTime = arriveTime; } public String getArriveDate(){ return arriveDate; } public void setArriveDate(String arriveDate){ this.arriveDate = arriveDate; } public String getFlyTime(){ return flyTime; } public void setFlyTime(String flyTime){ this.flyTime = flyTime; } public String getTicketPrice(){ return ticketPrice; } public void setTicketPrice(String ticketPrice){ this.ticketPrice = ticketPrice; } public int getAirlineLogo(){ return airlineLogo; } public void setAirlineLogo(int airlineLogo){ this.airlineLogo = airlineLogo; } } Error: .recyclerview.MainActivity}: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
Ответы
Ответ 1
Ошибка же очевидно говорит, что в Ваш стиль надо добавить итем- false
Ответ 2
Нашел ответ, твой ответ оказывается был близок...
Комментариев нет:
Отправить комментарий