Size: a a a

StartAndroid Ru Chat

2020 September 28

I

Ivan in StartAndroid Ru Chat
так может это не в хешмап дело
источник

I

Ivan in StartAndroid Ru Chat
это ListView?
источник

I

Ivan in StartAndroid Ru Chat
без кода ничего не понятно всё равно
источник

A

Asylzhan in StartAndroid Ru Chat
MutableList
источник

A

Asylzhan in StartAndroid Ru Chat
мне целый код скинуть?
источник

I

Ivan in StartAndroid Ru Chat
кидай, может кто-то сообразит
источник

A

Asylzhan in StartAndroid Ru Chat
class DataPump {
   fun getData(): HashMap<String, MutableList<String>> {
       val expandableListDetail: HashMap<String, MutableList<String>> = hashMapOf()

       val football: MutableList<String> = arrayListOf()
       football.add("Russia")
       football.add("USA")
       football.add("Kazakhstan")

       val basketball: MutableList<String> = arrayListOf()
       basketball.add("Russia")
       basketball.add("USA")
       basketball.add("Kazakhstan")

       val tennis: MutableList<String> = arrayListOf()
       tennis.add("Russia")
       tennis.add("USA")
       tennis.add("Kazakhstan")

       expandableListDetail.put("FOOTBALL", football)
       expandableListDetail.put("BASKETBALL", basketball)
       expandableListDetail.put("TENNIS", tennis)

       return expandableListDetail
   }
   fun getTitles(): MutableList<String>{
       val expandableListTitles: MutableList<String> = arrayListOf()
       expandableListTitles.add("Football")
       expandableListTitles.add("Basketball")
       expandableListTitles.add("Tennis")
       return expandableListTitles
   }
}
источник

A

Asylzhan in StartAndroid Ru Chat
class MainActivity : AppCompatActivity() {

   lateinit var expandableListView: ExpandableListView
   lateinit var expandableAdapter: CustomExpandableAdapter
   lateinit var expandableListDetail: HashMap<String, MutableList<String>>
   lateinit var expandableListTitle: MutableList<String>
   

   override fun onCreate(savedInstanceState: Bundle?) {
       super.onCreate(savedInstanceState)
       setContentView(R.layout.activity_main)

       expandableListView = findViewById(R.id.expandablelistview)
       expandableListDetail = DataPump().getData()
       expandableListTitle = DataPump().getTitles()

       expandableAdapter = CustomExpandableAdapter(this, expandableListDetail, expandableListTitle)
       expandableListView.setAdapter(expandableAdapter)


   }
}
источник

A

Asylzhan in StartAndroid Ru Chat
class CustomExpandableAdapter(val context: Context, val expandableListDetail: HashMap<String, MutableList<String>>, val expandableListTitle: MutableList<String>): BaseExpandableListAdapter() {
   override fun getGroupCount(): Int {
       return expandableListTitle.size
   }

   override fun getChildrenCount(groupPosition: Int): Int {
       return expandableListDetail.size
   }

   override fun getGroup(groupPosition: Int): Any {
       return expandableListTitle[groupPosition]
   }

   override fun getChild(groupPosition: Int, childPosition: Int): String? {
       return expandableListDetail.get(groupPosition)?.get(childPosition)
   }

   override fun getGroupId(groupPosition: Int): Long {
       return groupPosition.toLong()
   }

   override fun getChildId(groupPosition: Int, childPosition: Int): Long {
       return childPosition.toLong()
   }

   override fun hasStableIds(): Boolean {
       return false
   }

   override fun getGroupView(
       groupPosition: Int,
       isExpanded: Boolean,
       convertView: View?,
       parent: ViewGroup?
   ): View? {
       val listTitle: String = getGroup(groupPosition) as String
       var mConvertView = convertView
       if (mConvertView == null){
           val layoutInflater: LayoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
           mConvertView = layoutInflater.inflate(R.layout.group_row, null)
       }
       val listTitleTextView: TextView? = mConvertView?.findViewById(R.id.group_tv)
       listTitleTextView?.typeface = Typeface.DEFAULT_BOLD
       listTitleTextView?.text = listTitle
       return mConvertView
   }

   override fun getChildView(
       groupPosition: Int,
       childPosition: Int,
       isLastChild: Boolean,
       convertView: View?,
       parent: ViewGroup?
   ): View? {
       val expandedListText = getChild(groupPosition, childPosition)
       var mConvertView = convertView
       if (mConvertView == null){
           val layoutInflater: LayoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
           mConvertView = layoutInflater.inflate(R.layout.item_row, null)
       }
       val expandedListTextView: TextView? = mConvertView?.findViewById(R.id.item_tv)
       expandedListTextView?.text = expandedListText
       return mConvertView
   }

   override fun isChildSelectable(groupPosition: Int, childPosition: Int): Boolean {
       return true
   }
}
источник

ДР

Дмитрий Рубцов 🇷🇺🔥... in StartAndroid Ru Chat
Asylzhan
class DataPump {
   fun getData(): HashMap<String, MutableList<String>> {
       val expandableListDetail: HashMap<String, MutableList<String>> = hashMapOf()

       val football: MutableList<String> = arrayListOf()
       football.add("Russia")
       football.add("USA")
       football.add("Kazakhstan")

       val basketball: MutableList<String> = arrayListOf()
       basketball.add("Russia")
       basketball.add("USA")
       basketball.add("Kazakhstan")

       val tennis: MutableList<String> = arrayListOf()
       tennis.add("Russia")
       tennis.add("USA")
       tennis.add("Kazakhstan")

       expandableListDetail.put("FOOTBALL", football)
       expandableListDetail.put("BASKETBALL", basketball)
       expandableListDetail.put("TENNIS", tennis)

       return expandableListDetail
   }
   fun getTitles(): MutableList<String>{
       val expandableListTitles: MutableList<String> = arrayListOf()
       expandableListTitles.add("Football")
       expandableListTitles.add("Basketball")
       expandableListTitles.add("Tennis")
       return expandableListTitles
   }
}
за такое и забанить могут))
источник

I

Ivan in StartAndroid Ru Chat
Asylzhan
class CustomExpandableAdapter(val context: Context, val expandableListDetail: HashMap<String, MutableList<String>>, val expandableListTitle: MutableList<String>): BaseExpandableListAdapter() {
   override fun getGroupCount(): Int {
       return expandableListTitle.size
   }

   override fun getChildrenCount(groupPosition: Int): Int {
       return expandableListDetail.size
   }

   override fun getGroup(groupPosition: Int): Any {
       return expandableListTitle[groupPosition]
   }

   override fun getChild(groupPosition: Int, childPosition: Int): String? {
       return expandableListDetail.get(groupPosition)?.get(childPosition)
   }

   override fun getGroupId(groupPosition: Int): Long {
       return groupPosition.toLong()
   }

   override fun getChildId(groupPosition: Int, childPosition: Int): Long {
       return childPosition.toLong()
   }

   override fun hasStableIds(): Boolean {
       return false
   }

   override fun getGroupView(
       groupPosition: Int,
       isExpanded: Boolean,
       convertView: View?,
       parent: ViewGroup?
   ): View? {
       val listTitle: String = getGroup(groupPosition) as String
       var mConvertView = convertView
       if (mConvertView == null){
           val layoutInflater: LayoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
           mConvertView = layoutInflater.inflate(R.layout.group_row, null)
       }
       val listTitleTextView: TextView? = mConvertView?.findViewById(R.id.group_tv)
       listTitleTextView?.typeface = Typeface.DEFAULT_BOLD
       listTitleTextView?.text = listTitle
       return mConvertView
   }

   override fun getChildView(
       groupPosition: Int,
       childPosition: Int,
       isLastChild: Boolean,
       convertView: View?,
       parent: ViewGroup?
   ): View? {
       val expandedListText = getChild(groupPosition, childPosition)
       var mConvertView = convertView
       if (mConvertView == null){
           val layoutInflater: LayoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
           mConvertView = layoutInflater.inflate(R.layout.item_row, null)
       }
       val expandedListTextView: TextView? = mConvertView?.findViewById(R.id.item_tv)
       expandedListTextView?.text = expandedListText
       return mConvertView
   }

   override fun isChildSelectable(groupPosition: Int, childPosition: Int): Boolean {
       return true
   }
}
expandableListDetail.get(groupPosition)?.get(childPosition)
это неверная строчка
источник

I

Ivan in StartAndroid Ru Chat
Asylzhan
class CustomExpandableAdapter(val context: Context, val expandableListDetail: HashMap<String, MutableList<String>>, val expandableListTitle: MutableList<String>): BaseExpandableListAdapter() {
   override fun getGroupCount(): Int {
       return expandableListTitle.size
   }

   override fun getChildrenCount(groupPosition: Int): Int {
       return expandableListDetail.size
   }

   override fun getGroup(groupPosition: Int): Any {
       return expandableListTitle[groupPosition]
   }

   override fun getChild(groupPosition: Int, childPosition: Int): String? {
       return expandableListDetail.get(groupPosition)?.get(childPosition)
   }

   override fun getGroupId(groupPosition: Int): Long {
       return groupPosition.toLong()
   }

   override fun getChildId(groupPosition: Int, childPosition: Int): Long {
       return childPosition.toLong()
   }

   override fun hasStableIds(): Boolean {
       return false
   }

   override fun getGroupView(
       groupPosition: Int,
       isExpanded: Boolean,
       convertView: View?,
       parent: ViewGroup?
   ): View? {
       val listTitle: String = getGroup(groupPosition) as String
       var mConvertView = convertView
       if (mConvertView == null){
           val layoutInflater: LayoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
           mConvertView = layoutInflater.inflate(R.layout.group_row, null)
       }
       val listTitleTextView: TextView? = mConvertView?.findViewById(R.id.group_tv)
       listTitleTextView?.typeface = Typeface.DEFAULT_BOLD
       listTitleTextView?.text = listTitle
       return mConvertView
   }

   override fun getChildView(
       groupPosition: Int,
       childPosition: Int,
       isLastChild: Boolean,
       convertView: View?,
       parent: ViewGroup?
   ): View? {
       val expandedListText = getChild(groupPosition, childPosition)
       var mConvertView = convertView
       if (mConvertView == null){
           val layoutInflater: LayoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
           mConvertView = layoutInflater.inflate(R.layout.item_row, null)
       }
       val expandedListTextView: TextView? = mConvertView?.findViewById(R.id.item_tv)
       expandedListTextView?.text = expandedListText
       return mConvertView
   }

   override fun isChildSelectable(groupPosition: Int, childPosition: Int): Boolean {
       return true
   }
}
что ты хочешь достать по groupPosition, если у тебя HashMap<String, List> ?
источник

A

Asylzhan in StartAndroid Ru Chat
и как мне это исправить, я хотел просто достать элементы из MutableList
источник

A

Asylzhan in StartAndroid Ru Chat
Дмитрий Рубцов 🇷🇺🔥
за такое и забанить могут))
знаю, но это просто учеба
источник

I

Ivan in StartAndroid Ru Chat
Asylzhan
и как мне это исправить, я хотел просто достать элементы из MutableList
ты знаешь что такое HashMap и для чего она нужна?
источник

A

Asylzhan in StartAndroid Ru Chat
я еще учусь так что нет
источник

I

Ivan in StartAndroid Ru Chat
а также что HashMap не хранит порядок элементов, то есть каждый раз список у тебя может быть отсортирован как угодно?
источник

A

Asylzhan in StartAndroid Ru Chat
да
источник

I

Ivan in StartAndroid Ru Chat
Разберись, пожалуйста, с Java-коллекциями (в частности Map, HashMap, LinkedHashMap, TreeMap)
источник

I

Ivan in StartAndroid Ru Chat
и почему нельзя из HashMap достать по индексу.
источник