-
Notifications
You must be signed in to change notification settings - Fork 0
/
molongoActivity.java
69 lines (57 loc) · 3.18 KB
/
molongoActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.example.rental;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SearchView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.annotation.SuppressLint;
import android.os.Bundle;
import java.util.ArrayList;
public class MlolongoActivity extends AppCompatActivity {
SearchView searchView;
RecyclerView recyclerView;
ArrayList<ModelClassMlolongo> arrayList = new ArrayList<>();
ArrayList<ModelClassMlolongo> searchList;
String[] apartmentList = new String[]{"Westlands Avenue\t Serenity Apartment", "Parklands Road \tPineview Apartment", "Mtiti Road \t Sunset palms Apartment",
"Sport Road \t Lakeview Apartment", "Crossway \t Willow Springs Apartment",
"Ring Road \t Golden Gate Apartment", "Lower Kabete Road \t Azure Sky Apartment",
"Karuna Road \t Tranquil Waters Apartment", "Westlands Roundabout \t Avalon Apartment"
, "Westlands Expressway Entry \t Highlands Apartment"};
String[] apartmentNum = new String[]{"2-Bedroom\n Price $200 per month", "4-Bedroom\n Price $500 per month",
"Single Room \n $100 per month", "3-Bedroom\n $350 per month", "Single Room \n $150 Per Month",
"2-Bedroom \n $200 Per Month", "4-Bedroom \n $450 Per Month", "Single Room \n $170 Per Month",
"3-Bedroom \n $300 Per Month", "4-Bedroom \n $650 per Month"};
int[] imgList = new int[]{R.drawable.mlolongo1, R.drawable.mlolongo2, R.drawable.mlolongo3,
R.drawable.mlolongo4, R.drawable.mlolongo5, R.drawable.mlolongo6,
R.drawable.r11, R.drawable.r12, R.drawable.r7, R.drawable.r15};
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mlolongo);
searchView = findViewById(R.id.searchview);
recyclerView = findViewById(R.id.recyclerview);
for (int i = 0; i < Math.min(apartmentList.length, Math.min(apartmentNum.length, imgList.length)); i++) {
ModelClassMlolongo modelClassMlolongo = new ModelClassMlolongo();
modelClassMlolongo.setApartmentName(apartmentList[i]);
modelClassMlolongo.setApartmentNum(apartmentNum[i]);
modelClassMlolongo.setImg(imgList[i]);
arrayList.add(modelClassMlolongo);
}
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(MlolongoActivity.this);
recyclerView.setLayoutManager(layoutManager);
final MlolongoAdapter mlolongoAdapter = new MlolongoAdapter(MlolongoActivity.this, arrayList);
recyclerView.setAdapter(mlolongoAdapter);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
mlolongoAdapter.getFilter().filter(query);
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
mlolongoAdapter.getFilter().filter(newText);
return false;
}
});
}
}