Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.a1.bottombar;
- import android.app.ActionBar;
- import android.content.Intent;
- import android.graphics.Color;
- import android.os.Bundle;
- import android.support.annotation.NonNull;
- import android.support.design.widget.BottomNavigationView;
- import android.support.v7.app.AppCompatActivity;
- import android.util.Log;
- import android.view.MenuItem;
- import android.view.View;
- import android.widget.AdapterView;
- import android.widget.LinearLayout;
- import android.widget.ListView;
- import android.widget.SimpleAdapter;
- import android.widget.TextView;
- import java.util.ArrayList;
- import java.util.HashMap;
- public class MainActivity extends AppCompatActivity {
- LinearLayout linearLayout;
- ListView listView;
- SimpleAdapter theory;
- private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
- = new BottomNavigationView.OnNavigationItemSelectedListener() {
- @Override
- public boolean onNavigationItemSelected(@NonNull MenuItem item) {
- linearLayout.removeAllViews();
- switch (item.getItemId()) {
- case R.id.theory:
- linearLayout.addView(listView);
- return true;
- case R.id.test:
- return true;
- }
- return false;
- }
- };
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- linearLayout = findViewById(R.id.mainLayout);
- listView = new ListView(this);
- listView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
- LinearLayout.LayoutParams.MATCH_PARENT));
- linearLayout.addView(listView);
- BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
- navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
- final AdapterAdder theoryArray = new AdapterAdder("Header", "Text");
- String[] orig = getResources().getStringArray(R.array.menu_orig);
- String[] local = getResources().getStringArray(R.array.menu_ru);
- for (int i = 0; i < orig.length; i++) {
- theoryArray.put(orig[i], local[i]);
- }
- theory = new SimpleAdapter(this,
- theoryArray.toArrayList(),
- R.layout.list_item,
- new String[]{"Header", "Text"},
- new int[]{R.id.text1, R.id.text2});
- listView.setAdapter(theory);
- listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View itemClicked, int position, long id) {
- Intent intent = new Intent(MainActivity.this, TheoryActivity.class);
- intent.putExtra("Title", (String) theoryArray.getByID(position).get("Text"));
- intent.putExtra("orig", (String) theoryArray.getByID(position).get("Header"));
- startActivity(intent);
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement