Guest User

Untitled

a guest
Oct 17th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical" android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:clickable="true"
  6. android:focusable="true"
  7. android:background="#ffffff">
  8.  
  9. <EditText
  10. android:layout_width="match_parent"
  11. android:layout_height="wrap_content"
  12. android:inputType="textPersonName"
  13. android:ems="10"
  14. android:id="@+id/editableText"
  15. android:layout_gravity="center_horizontal"
  16. android:editable="true"
  17. android:hint="Search Here"
  18. android:padding="20dp"
  19. android:layout_marginTop="10dp"
  20. android:layout_marginBottom="10dp" />
  21.  
  22. <ListView
  23.  
  24. android:id="@+id/listSearch"
  25. android:layout_width="match_parent"
  26. android:layout_height="wrap_content"
  27. android:footerDividersEnabled="false"
  28. android:headerDividersEnabled="false"
  29. android:paddingStart="15dp"
  30. android:paddingEnd="15dp" />
  31.  
  32. </LinearLayout>
  33.  
  34. @Override
  35. public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedBundle) {
  36.  
  37. View firstAccessView;
  38. if(savedBundle==null) {
  39. firstAccessView = inflater.inflate(R.layout.search_fragment_layout, null);
  40.  
  41. ((ActionBarActivity)getActivity()).getSupportActionBar().setTitle("Search Friend");
  42.  
  43. for(int i=0; i<8; i++){
  44. Contact c = new Contact(idContact[i], nameSurname[i], facebookId[i], timeStamp[i]);
  45. this.rows.add(c);
  46.  
  47. }
  48.  
  49.  
  50. adapter = new SearchListAdapter(getActivity(), this.rows);
  51. list = (ListView) firstAccessView.findViewById(R.id.listSearch);
  52. list.setAdapter(adapter);
  53.  
  54. list.setOnScrollListener(this);
  55. list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  56.  
  57. @Override
  58. public void onItemClick(AdapterView<?> parent, View view,
  59. int position, long id) {
  60. //TODO Auto-generated method stub
  61.  
  62. Toast.makeText(getActivity().getApplicationContext(), "item selected", Toast.LENGTH_SHORT).show();
  63.  
  64. }
  65. });
  66.  
  67. this.editableText = (TextView) firstAccessView.findViewById(R.id.editableText);
  68. this.editableText.addTextChangedListener(new TextWatcher() {
  69. @Override
  70. public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  71.  
  72. }
  73.  
  74. @Override
  75. public void onTextChanged(CharSequence s, int start, int before, int count) {
  76. List<Contact> temp = new ArrayList<Contact>();
  77. int length = editableText.getText().length();
  78. temp.clear();
  79. for(int i = 0; i<rows.size(); i++){
  80. if(editableText.getText().toString().equalsIgnoreCase("")){
  81. list.setAdapter(new SearchListAdapter(getActivity(), rows));
  82. }
  83. if(length < rows.get(i).getName().length()){
  84. if(editableText.getText().toString().equalsIgnoreCase((String)rows.get(i).getName().subSequence(0,length))){
  85. temp.add(rows.get(i));
  86.  
  87. }
  88. }
  89.  
  90. }
  91. if(temp.size()>0){
  92. list.setAdapter(new SearchListAdapter(getActivity(), temp));
  93. }
  94.  
  95. }
  96.  
  97. @Override
  98. public void afterTextChanged(Editable s) {
  99.  
  100. }
  101. });
  102.  
  103. }else{
  104. firstAccessView = getView();
  105. }
  106. return firstAccessView;
  107. }
  108.  
  109. list.setOnItemClickListener( new OnItemClickListener() {
  110. public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
  111. //code here
  112. });
Add Comment
Please, Sign In to add comment