From 3a934cd4866e9b5ec58c94a2522aa30b40271373 Mon Sep 17 00:00:00 2001 From: Sag0ld Date: Sat, 24 Mar 2018 21:41:49 -0400 Subject: [PATCH] list caline --- .../component/LostObjectsAdapter.kt | 23 +++-- .../fragment/ListSegmentFragment.kt | 16 ++-- .../app/src/main/res/layout/fragment_list.xml | 88 +------------------ android/app/src/main/res/layout/item.xml | 84 ++++++++++++++++++ 4 files changed, 109 insertions(+), 102 deletions(-) create mode 100644 android/app/src/main/res/layout/item.xml diff --git a/android/app/src/main/java/com/mirego/csmapapplication/component/LostObjectsAdapter.kt b/android/app/src/main/java/com/mirego/csmapapplication/component/LostObjectsAdapter.kt index 0dc8012..0498b74 100644 --- a/android/app/src/main/java/com/mirego/csmapapplication/component/LostObjectsAdapter.kt +++ b/android/app/src/main/java/com/mirego/csmapapplication/component/LostObjectsAdapter.kt @@ -1,6 +1,8 @@ package com.mirego.csmapapplication.component +import android.app.Activity import android.content.Context +import android.support.v4.app.FragmentActivity import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -9,30 +11,27 @@ import com.mirego.csmapapplication.R import android.widget.ImageView import android.widget.TextView - - - - /** * Created by Sagold on 2018-03-24. */ -class LostObjectsAdapter(private val context: Context, private val objects: ArrayList) : BaseAdapter() { +class LostObjectsAdapter(private val objects: ArrayList, private val activity: FragmentActivity) : BaseAdapter() { override fun getView(i: Int, p0: View?, viewGroup: ViewGroup?): View { var view = p0 if (view == null) { - view = LayoutInflater.from(viewGroup!!.context).inflate(R.layout.fragment_list, viewGroup, false) + view = View.inflate(activity,R.layout.item,null) } + val s = this.getItem(i) as String val img = view!!.findViewById(R.id.imageIcon) as ImageView - val description = view!!.findViewById(R.id.txtDescription) as TextView - val position = view!!.findViewById(R.id.txtPosition) as TextView - val distance = view!!.findViewById(R.id.txtDistance) as TextView - val name = view!!.findViewById(R.id.txtObjectName) as TextView + var description = view!!.findViewById(R.id.txtDescription) as TextView + var position = view!!.findViewById(R.id.txtPosition) as TextView + var distance = view!!.findViewById(R.id.txtDistance) as TextView + var name = view!!.findViewById(R.id.txtObjectName) as TextView - description.text = "ici" + description.text = "..." position.text = "jhdfhg" distance.text = "hjbfdh" name.text = "djfbhgbf" @@ -49,6 +48,6 @@ class LostObjectsAdapter(private val context: Context, private val objects: Arra } override fun getCount(): Int { - return objects.size + return objects.size; } } \ No newline at end of file diff --git a/android/app/src/main/java/com/mirego/csmapapplication/fragment/ListSegmentFragment.kt b/android/app/src/main/java/com/mirego/csmapapplication/fragment/ListSegmentFragment.kt index 68296f4..1aa8108 100644 --- a/android/app/src/main/java/com/mirego/csmapapplication/fragment/ListSegmentFragment.kt +++ b/android/app/src/main/java/com/mirego/csmapapplication/fragment/ListSegmentFragment.kt @@ -2,11 +2,10 @@ package com.mirego.csmapapplication.fragment import android.support.v4.app.Fragment import android.os.Bundle -import android.support.constraint.ConstraintLayout import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.FrameLayout +import android.widget.ArrayAdapter import android.widget.ListView import com.mirego.csmapapplication.R import com.mirego.csmapapplication.component.LostObjectsAdapter @@ -20,11 +19,16 @@ class ListSegmentFragment : Fragment() { savedInstanceState: Bundle? ): View? { val view = inflater.inflate(R.layout.fragment_list, container, false) - val constraintLayout = view.findViewById(R.id.container) as ConstraintLayout - val listView = ListView(context) - val adapter = LostObjectsAdapter(context!!, ArrayList()) + val listView = view.findViewById(R.id.listContainer) as ListView + + val list = ArrayList() + var adapterlist : ArrayAdapter?=null + list.add("Hello") + list.add("Hello 1") + list.add("Hello 2") + adapterlist = ArrayAdapter(activity!!,android.R.layout.simple_list_item_1,list) + val adapter = LostObjectsAdapter(list, activity!!) listView.adapter = adapter - constraintLayout.addView(listView) return view } } diff --git a/android/app/src/main/res/layout/fragment_list.xml b/android/app/src/main/res/layout/fragment_list.xml index a790017..13a78c3 100644 --- a/android/app/src/main/res/layout/fragment_list.xml +++ b/android/app/src/main/res/layout/fragment_list.xml @@ -3,89 +3,9 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" - android:id="@+id/container"> - - - + - - - - - - - - - - - - - - - - - - - - - - - + android:layout_height="match_parent" + android:id="@+id/listContainer"/> \ No newline at end of file diff --git a/android/app/src/main/res/layout/item.xml b/android/app/src/main/res/layout/item.xml new file mode 100644 index 0000000..e40212a --- /dev/null +++ b/android/app/src/main/res/layout/item.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file