Advertisement
Pit_Anonim

Untitled

Apr 17th, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. package com.example.a1.bottombar;
  2.  
  3. import android.app.ActionBar;
  4. import android.content.Intent;
  5. import android.graphics.Color;
  6. import android.os.Bundle;
  7. import android.support.annotation.NonNull;
  8. import android.support.design.widget.BottomNavigationView;
  9. import android.support.v7.app.AppCompatActivity;
  10. import android.util.Log;
  11. import android.view.MenuItem;
  12. import android.view.View;
  13. import android.widget.AdapterView;
  14. import android.widget.LinearLayout;
  15. import android.widget.ListView;
  16. import android.widget.SimpleAdapter;
  17. import android.widget.TextView;
  18.  
  19. import java.util.ArrayList;
  20. import java.util.HashMap;
  21.  
  22. public class MainActivity extends AppCompatActivity {
  23.  
  24. LinearLayout linearLayout;
  25. ListView listView;
  26. SimpleAdapter theory;
  27.  
  28.  
  29. private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
  30. = new BottomNavigationView.OnNavigationItemSelectedListener() {
  31.  
  32. @Override
  33. public boolean onNavigationItemSelected(@NonNull MenuItem item) {
  34. linearLayout.removeAllViews();
  35. switch (item.getItemId()) {
  36. case R.id.theory:
  37. linearLayout.addView(listView);
  38. return true;
  39. case R.id.test:
  40. return true;
  41. }
  42. return false;
  43. }
  44. };
  45.  
  46. @Override
  47. protected void onCreate(Bundle savedInstanceState) {
  48. super.onCreate(savedInstanceState);
  49. setContentView(R.layout.activity_main);
  50.  
  51. linearLayout = findViewById(R.id.mainLayout);
  52. listView = new ListView(this);
  53. listView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
  54. LinearLayout.LayoutParams.MATCH_PARENT));
  55. linearLayout.addView(listView);
  56.  
  57. BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
  58. navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
  59.  
  60.  
  61. final AdapterAdder theoryArray = new AdapterAdder("Header", "Text");
  62.  
  63. String[] orig = getResources().getStringArray(R.array.menu_orig);
  64. String[] local = getResources().getStringArray(R.array.menu_ru);
  65.  
  66. for (int i = 0; i < orig.length; i++) {
  67. theoryArray.put(orig[i], local[i]);
  68. }
  69.  
  70. theory = new SimpleAdapter(this,
  71. theoryArray.toArrayList(),
  72. R.layout.list_item,
  73. new String[]{"Header", "Text"},
  74. new int[]{R.id.text1, R.id.text2});
  75. listView.setAdapter(theory);
  76.  
  77. listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  78. @Override
  79. public void onItemClick(AdapterView<?> parent, View itemClicked, int position, long id) {
  80. Intent intent = new Intent(MainActivity.this, TheoryActivity.class);
  81. intent.putExtra("Title", (String) theoryArray.getByID(position).get("Text"));
  82. intent.putExtra("orig", (String) theoryArray.getByID(position).get("Header"));
  83. startActivity(intent);
  84.  
  85. }
  86. });
  87. }
  88.  
  89.  
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement