Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
ElBuenoPeso
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Matis SPINELLI
ElBuenoPeso
Commits
d95f8def
Commit
d95f8def
authored
Feb 21, 2024
by
Timothé KOBAK
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
grid view implemented
parent
b2bc3455
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
100 additions
and
45 deletions
+100
-45
MarketFragment.kt
.../java/com/example/elbuenopeso/ui/market/MarketFragment.kt
+45
-14
fragment_market.xml
app/src/main/res/layout/fragment_market.xml
+29
-4
item_listview_ad.xml
app/src/main/res/layout/item_listview_ad.xml
+26
-27
No files found.
app/src/main/java/com/example/elbuenopeso/ui/market/MarketFragment.kt
View file @
d95f8def
...
...
@@ -5,7 +5,9 @@ import android.os.Bundle
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.widget.GridView
import
android.widget.ListView
import
android.widget.ToggleButton
import
androidx.fragment.app.Fragment
import
androidx.lifecycle.ViewModelProvider
import
com.example.elbuenopeso.databinding.FragmentMarketBinding
...
...
@@ -15,25 +17,30 @@ import com.example.elbuenopeso.R
class
MarketFragment
:
Fragment
()
{
private
var
_binding
:
FragmentMarketBinding
?
=
null
// This property is only valid between onCreateView and
// onDestroyView.
private
val
binding
get
()
=
_binding
!!
private
lateinit
var
listView
:
ListView
private
lateinit
var
gridView
:
GridView
private
lateinit
var
toggleButton
:
ToggleButton
private
lateinit
var
adAdapter
:
AdAdapter
private
var
isGridViewEnabled
=
false
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?
):
View
{
val
marketViewModel
=
ViewModelProvider
(
this
)[
MarketViewModel
::
class
.
java
]
_binding
=
FragmentMarketBinding
.
inflate
(
inflater
,
container
,
false
)
val
root
:
View
=
binding
.
root
val
listView
:
ListView
=
binding
.
listView
// seed market items
var
annonces
:
List
<
AdModel
>
=
listOf
<
AdModel
>(
listView
=
binding
.
listView
gridView
=
binding
.
gridView
toggleButton
=
binding
.
toggleButton
val
annonces
:
List
<
AdModel
>
=
listOf
(
AdModel
(
"Poutre"
,
"1 rue Jean-Pierre"
,
R
.
drawable
.
pichu
,
25.0
),
AdModel
(
"Briques"
,
"2 rue Jean-Michel"
,
R
.
drawable
.
pichu
,
16.0
),
AdModel
(
"Poutre"
,
"1 rue Jean-Pierre"
,
R
.
drawable
.
pichu
,
25.0
),
AdModel
(
"Briques"
,
"2 rue Jean-Michel"
,
R
.
drawable
.
pichu
,
16.0
),
AdModel
(
"Mur en bois"
,
"4 rue Alain-Juju"
,
R
.
drawable
.
pichu
,
7.2
),
...
...
@@ -43,19 +50,43 @@ class MarketFragment : Fragment() {
AdModel
(
"Charnières"
,
"22 rue Jeanne-Marie"
,
R
.
drawable
.
pichu
,
2648.97
),
AdModel
(
"Porte en marbre"
,
"1 rue Jean-Pierre"
,
R
.
drawable
.
pichu
,
480.0
),
AdModel
(
"Cheminée"
,
"33 rue du Gouvernement"
,
R
.
drawable
.
pichu
,
800.0
),
AdModel
(
"Poutre"
,
"1 rue Jean-Pierre"
,
R
.
drawable
.
pichu
,
25.0
),
AdModel
(
"Briques"
,
"2 rue Jean-Michel"
,
R
.
drawable
.
pichu
,
16.0
),
AdModel
(
"Mur en bois"
,
"4 rue Alain-Juju"
,
R
.
drawable
.
pichu
,
7.2
),
AdModel
(
"Maison de pierre"
,
"7 rue Joris Belhomme"
,
R
.
drawable
.
pichu
,
3.99
),
AdModel
(
"Téléphone de Timothé"
,
"8 rue de Timothé"
,
R
.
drawable
.
pichu
,
0.85
),
AdModel
(
"Oridnateur"
,
"10 rue Jean-Charles"
,
R
.
drawable
.
pichu
,
104.98
),
AdModel
(
"Charnières"
,
"22 rue Jeanne-Marie"
,
R
.
drawable
.
pichu
,
2648.97
),
AdModel
(
"Porte en marbre"
,
"1 rue Jean-Pierre"
,
R
.
drawable
.
pichu
,
480.0
),
AdModel
(
"Cheminée"
,
"33 rue du Gouvernement"
,
R
.
drawable
.
pichu
,
800.0
),
// Add more AdModel items as needed
)
var
adAdapter
:
A
dAdapter
=
AdAdapter
(
requireContext
(),
annonces
)
a
dAdapter
=
AdAdapter
(
requireContext
(),
annonces
)
listView
.
adapter
=
adAdapter
/*marketViewModel.text.observe(viewLifecycleOwner) {
textView.text = it
}*/
toggleButton
.
setOnCheckedChangeListener
{
_
,
isChecked
->
isGridViewEnabled
=
isChecked
updateView
()
}
return
root
}
private
fun
updateView
()
{
if
(
isGridViewEnabled
)
{
listView
.
visibility
=
View
.
GONE
gridView
.
visibility
=
View
.
VISIBLE
gridView
.
adapter
=
adAdapter
}
else
{
gridView
.
visibility
=
View
.
GONE
listView
.
visibility
=
View
.
VISIBLE
listView
.
adapter
=
adAdapter
}
}
override
fun
onDestroyView
()
{
super
.
onDestroyView
()
_binding
=
null
}
}
\ No newline at end of file
}
app/src/main/res/layout/fragment_market.xml
View file @
d95f8def
...
...
@@ -6,12 +6,37 @@
android:layout_height=
"match_parent"
tools:context=
".ui.market.MarketFragment"
>
<ToggleButton
android:id=
"@+id/toggleButton"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Toggle View"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
<ListView
android:id=
"@+id/listView"
android:layout_width=
"409dp"
android:layout_height=
"681dp"
android:layout_width=
"0dp"
android:layout_height=
"0dp"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
app:layout_constraintTop_toBottomOf=
"@id/toggleButton"
/>
<GridView
android:id=
"@+id/gridView"
android:layout_width=
"0dp"
android:layout_height=
"0dp"
android:numColumns=
"2"
android:stretchMode=
"columnWidth"
android:gravity=
"center"
android:horizontalSpacing=
"8dp"
android:verticalSpacing=
"8dp"
android:padding=
"8dp"
android:visibility=
"gone"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@id/toggleButton"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
</androidx.constraintlayout.widget.ConstraintLayout>
app/src/main/res/layout/item_listview_ad.xml
View file @
d95f8def
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<TextView
android:id=
"@+id/itemListViewTitleView"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"TextView"
android:textSize=
"20sp"
app:layout_constraintStart_toEndOf=
"@+id/itemListViewImageView"
app:layout_constraintTop_toTopOf=
"parent"
/>
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
android:padding=
"8dp"
>
<ImageView
android:id=
"@+id/itemListViewImageView"
android:layout_width=
"117dp"
android:layout_height=
"94dp"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
tools:srcCompat=
"@drawable/pichu"
/>
android:layout_gravity=
"center_horizontal"
android:src=
"@drawable/pichu"
/>
<TextView
android:id=
"@+id/itemListViewT
ext
View"
android:layout_width=
"
wrap_cont
ent"
android:id=
"@+id/itemListViewT
itle
View"
android:layout_width=
"
match_par
ent"
android:layout_height=
"wrap_content"
android:text=
"TextView"
app:layout_constraintBottom_toBottomOf=
"@+id/itemListViewImageView"
app:layout_constraintStart_toEndOf=
"@+id/itemListViewImageView"
/>
android:textSize=
"20sp"
android:textStyle=
"bold"
android:maxLines=
"2"
android:ellipsize=
"end"
android:paddingTop=
"8dp"
android:paddingBottom=
"4dp"
/>
<TextView
android:id=
"@+id/itemListViewPrixView"
android:layout_width=
"wrap_content"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:textSize=
"16sp"
android:paddingBottom=
"4dp"
/>
<TextView
android:id=
"@+id/itemListViewTextView"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:text=
"TextView"
app:layout_constraintBottom_toTopOf=
"@+id/itemListViewTextView"
app:layout_constraintStart_toEndOf=
"@+id/itemListViewImageView"
app:layout_constraintTop_toBottomOf=
"@+id/itemListViewTitleView"
/>
android:textSize=
"14sp"
android:maxLines=
"3"
android:ellipsize=
"end"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
</LinearLayout>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment