• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

help..i am stuck

ali1974canada

Lurker
Feb 27, 2020
3
0
package com.example.dependentspinners

import android.R
import android.os.Bundle
import android.view.View
import android.widget.ArrayAdapter
import android.widget.Spinner
import androidx.appcompat.app.AppCompatActivity
import java.util.*


class MainActivity : AppCompatActivity() {
var sp_parent: Spinner? = null
var sp_child: Spinner? = null
var arrayList_parent: ArrayList<String>? = null
var arrayAdapter_parent: ArrayAdapter<String>? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
sp_parent = findViewById<View>(R.id.sp_parent) as Spinner
sp_child = findViewById<View>(R.id.sp_child) as Spinner
arrayList_parent = ArrayList()
arrayList_parent!!.add("Service")
arrayList_parent!!.add("lawyer")
arrayList_parent!!.add("pigs")
arrayAdapter_parent = ArrayAdapter(
applicationContext,
R.layout.simple_spinner_item,
arrayList_parent!!
)
sp_parent!!.adapter = arrayAdapter_parent
}
}
 
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:eek:rientation="vertical"
tools:context=".MainActivity"
android:padding="20dp">

<TextView
android:id="@+id/parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@String/parent"
android:textColor="#00f"
android:textSize="20sp"
/>

<Spinner
android:id="@+id/sp_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"

/>

<TextView
android:id="@+id/child"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@String/parent"
android:textColor="#f00"
android:textSize="20sp"
android:layout_marginTop="100dp"
/>

<Spinner
android:id="@+id/Sp_child"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"

/>
</LinearLayout>
 
Upvote 0
It might help if you told us (well, the developers in the house, at least) what you're trying to accomplish and what's going wrong. It's good to include the relevant code snippets (of course) but that doesn't really tell us anything about the problem.

Pro-tip: you can use [code]...[/code] tags to make your code a bit easier to read.
 
  • Like
Reactions: Unforgiven
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones