Advertisement
Guest User

Untitled

a guest
Jan 13th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.54 KB | None | 0 0
  1. package com.example.akisha.myapplication;
  2.  
  3. import android.content.Intent;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.os.Bundle;
  6. import android.text.Editable;
  7. import android.text.TextWatcher;
  8. import android.view.MenuItem;
  9. import android.view.View;
  10. import android.widget.AdapterView;
  11. import android.widget.ArrayAdapter;
  12. import android.widget.EditText;
  13. import android.widget.ListView;
  14. import android.widget.Toast;
  15.  
  16. import java.util.ArrayList;
  17. import java.util.Arrays;
  18. import java.util.HashMap;
  19.  
  20. public class About extends AppCompatActivity {
  21.  
  22. EditText e1;
  23. ListView l1;
  24.  
  25. String[] items;
  26. ArrayAdapter<String> adapter;
  27. ArrayList<String>arrayList;
  28.  
  29. @Override
  30. protected void onCreate(Bundle savedInstanceState) {
  31. super.onCreate(savedInstanceState);
  32. setContentView(R.layout.activity_about);
  33.  
  34. e1 = (EditText) findViewById(R.id.editText);
  35. l1 = (ListView) findViewById(R.id.list_view);
  36. items = new String[] {"Pakista","Europe","America"};
  37. arrayList = new ArrayList<>(Arrays.asList(items));
  38. adapter = new ArrayAdapter<>(this,R.layout.list_item,R.id.name,arrayList);
  39. l1.setTextFilterEnabled(true);
  40. l1.setAdapter(adapter);
  41.  
  42.  
  43. l1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  44.  
  45. @Override
  46. public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  47. if (position == 0) {
  48. Intent intent = new Intent(view.getContext(), Jeproks.class);
  49. startActivityForResult(intent, 0);
  50. } else if (position == 1) {
  51. Intent intent = new Intent(view.getContext(), Adidas.class);
  52. startActivityForResult(intent, 0);
  53. } else if (position == 2) {
  54. Intent intent = new Intent(view.getContext(), Alat.class);
  55. startActivityForResult(intent, 0);
  56. } else if (position == 3) {
  57. Intent intent = new Intent(view.getContext(), Apir.class);
  58. startActivityForResult(intent, 0);
  59. } else if (position == 4) {
  60. Intent intent = new Intent(view.getContext(), Apog.class);
  61. startActivityForResult(intent, 0);
  62. } else if (position == 5) {
  63. Intent intent = new Intent(view.getContext(), Astig.class);
  64. startActivityForResult(intent, 0);
  65. } else if (position == 6) {
  66. Intent intent = new Intent(view.getContext(), Atat.class);
  67. startActivityForResult(intent, 0);
  68. } else if (position == 7) {
  69. Intent intent = new Intent(view.getContext(), Atik.class);
  70. startActivityForResult(intent, 0);
  71. }
  72. Toast.makeText(About.this, items[position], Toast.LENGTH_SHORT).show();
  73. }
  74. });
  75.  
  76.  
  77.  
  78. e1.addTextChangedListener(new TextWatcher() {
  79. @Override
  80. public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
  81.  
  82.  
  83. }
  84.  
  85. @Override
  86. public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
  87. About.this.adapter.getFilter().filter(charSequence);
  88. adapter.notifyDataSetChanged();
  89.  
  90. }
  91.  
  92. @Override
  93. public void afterTextChanged(Editable editable) {
  94.  
  95. }
  96. });
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement