標題:
Spinner
[打印本頁]
作者:
周政輝
時間:
2018-11-24 10:27
標題:
Spinner
[attach]5346[/attach]
[attach]5347[/attach]
作者:
李知易
時間:
2018-12-8 08:44
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:layout_editor_absoluteY="8dp">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="最喜歡的食物"
android:textSize="24sp" />
<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/show"
android:layout_width="match_parent"
android:layout_height="58dp"
android:gravity="center_horizontal"
android:textSize="36sp" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
複製代碼
作者:
李知易
時間:
2018-12-8 08:45
package com.example.eli.hw20181208;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView show = (TextView) findViewById(R.id.show);
final TextView textView = (TextView) findViewById(R.id.textView);
Spinner spinner = (Spinner) findViewById(R.id.spinner);
final String[] food = {"雞腿飯", "魯肉飯", "排骨飯", "水餃", "陽春麵"};
ArrayAdapter<String> foodlist = new ArrayAdapter<>(MainActivity.this,
android.R.layout.simple_spinner_dropdown_item,
food);
spinner.setAdapter(foodlist);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
show.setText(food[position]);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
}
複製代碼
作者:
張健勳
時間:
2018-12-8 10:39
package com.smcs.yingwu.spinner;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView tvs = findViewById(R.id.tvs);
Spinner sp = findViewById(R.id.sp);
final String[] game = {"CS:GO","LOL","GTA5","PUBG"};
ArrayAdapter<String> gamel = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_spinner_dropdown_item, game);
sp.setAdapter(gamel);
sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
tvs.setText(game[position]);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
}
複製代碼
作者:
洪振庭
時間:
2018-12-8 10:51
package com.example.student.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView show = (TextView) findViewById(R.id.show);
final TextView textView = (TextView) findViewById(R.id.textView);
Spinner spinner = (Spinner) findViewById(R.id.spinner);
final String[] sport={"慢跑","籃球","游泳","乒乓球","羽毛球"};
ArrayAdapter<String> sportlist = new ArrayAdapter<>(MainActivity.this,
android.R.layout.simple_spinner_dropdown_item,
sport);
spinner.setAdapter(sportlist);
spinner.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
show.setText(sport[position]);
}
public void onNothingSelected(AdapterView<?> parent){}
});
}
}
複製代碼
作者:
陳泓瑜
時間:
2018-12-8 10:56
package com.example.student.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView textView;
Spinner spinner;
final String[] text ={"A","B","C","D","E"};
textView = (TextView) findViewById(R.id.textView);
spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<String> textlist = new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_dropdown_item_1line,text);
spinner.setAdapter(textlist);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
textView.setText(text[position]);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
}
複製代碼
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/spinner"
android:layout_column="0" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="90sp"
android:text="New Text"
android:id="@+id/textView"
android:layout_column="0"
android:gravity="center"
android:background="#35274235"
android:textSize="45sp" />
</TableRow>
</TableLayout>
複製代碼
作者:
黃璽安
時間:
2018-12-8 11:00
package com.example.student.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView tv = findViewById(R.id.TextView);
Spinner sp = findViewById(R.id.Spinner);
final String[] game = {"蘋果","漢堡","牛排","蔬菜"};
ArrayAdapter<String> gamel = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_spinner_dropdown_item, game);
sp.setAdapter(gamel);
sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
tv.setText(game[position]);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
}
複製代碼
作者:
蔡季樺
時間:
2018-12-14 19:38
package com.example.plantsai.myapplicationspinner;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
String names[]={"烤雞","龍蝦","披薩","沙拉","牛排"};
Spinner spinner;
ArrayAdapter arrayAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
spinner = findViewById(R.id.spinner);
arrayAdapter = new ArrayAdapter(this,R.layout.sp_tv,names);
spinner.setAdapter(arrayAdapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(MainActivity.this,"您點了一份"+names[position],Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
}
複製代碼
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Spinner
android:id="@+id/spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="40dp"
android:layout_marginStart="40dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.115" />
</android.support.constraint.ConstraintLayout>
複製代碼
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="24sp"></TextView>
複製代碼
作者:
蔡庭豪
時間:
2018-12-14 20:13
package com.example.student.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
String menu[] = {"羽球","籃球","排球","游泳","乒乓球"};
ArrayAdapter arrayAdapter;
Spinner sp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sp = (Spinner) findViewById(R.id.spinner);
arrayAdapter = new ArrayAdapter(this,R.layout.support_simple_spinner_dropdown_item,menu);
sp.setAdapter(arrayAdapter);
sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(MainActivity.this, String.format("你喜歡%s", menu[position]),Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
}
複製代碼
作者:
蔡庭豪
時間:
2018-12-14 20:40
package com.example.student.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
String menu[] = {"羽球","籃球","排球","游泳","乒乓球"};
MyAdapater arrayAdapter;
Spinner sp;
ImageView image[] = ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sp = (Spinner) findViewById(R.id.spinner);
arrayAdapter = new MyAdapater(this,R.layout.support_simple_spinner_dropdown_item,menu,image);
sp.setAdapter(arrayAdapter);
sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(MainActivity.this, String.format("你喜歡%s", menu[position]),Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
}
複製代碼
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="烤雞"
android:id="@+id/textView2"
android:layout_below="@+id/imageView"
android:layout_toEndOf="@+id/imageView"
android:layout_marginStart="34dp" />
</RelativeLayout>
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2