11111111111111111111111111111111111111111111111111111111111111111111111111111
xml:xml:xml:xml:xml:xml:xml:xml:xml:xml:xml:xml:xml:xml:xml:xml:xml:xml:xml:xml:xml:
11111111111111111111111111111111111111111111111111111111111111111111111111111
java:java:java:java:java:java:java:java:java:java:java:java:java:java:java:
package com.example.spinner_siver;
import androidx.appcompat.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;
import android.widget.Toast;
import java.lang.reflect.Array;
public class MainActivity extends AppCompatActivity {
Spinner spinner_1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
spinner_1 = findViewById(R.id.spinner_1);
String[] arr1 = {"全部", "纪录片", "动画片", "音乐", "漫画", "舞蹈"};
ArrayAdapter adapter = new ArrayAdapter(MainActivity.this, androidx.appcompat.R.layout.support_simple_spinner_dropdown_item, arr1);
spinner_1.setAdapter(adapter);
spinner_1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView> adapterView, View view, int i, long l) {
TextView text = (TextView)view;
String str = text.getText().toString();
Toast.makeText(MainActivity.this, "你选择了"+str, Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView> adapterView) {
}
});
}
}
22222222222222222222222222222222222222222222222222222222222222
xml:xml:xml:xml:xml:xml:xml:xml:xml:xml:xml:xml:xml:xml:xml:xml:xml:xml:xml:xml:xml:
22222222222222222222222222222222222222222222222222222222222222
java:java:java:java:java:java:java:java:java:java:java:java:java:java:java:
public class MainActivity2 extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
//定义控件
TextView Text_showname;
TextView Text_showbirth;
ImageView img_star;
TextView Text_showstar;
//绑定控件
Text_showname = findViewById(R.id.TEXTVIEW_SHOWNAME);
Text_showbirth = findViewById(R.id.TEXTVIEW_SHOWBIRTH);
img_star = findViewById(R.id.IMAGE_STAR);
Text_showstar = findViewById(R.id.TEXTVIEW_STAR);
//接收第一页传递过来的值并显示在对应的文本控件上
String str_name = getIntent().getStringExtra("input_name");
Text_showname.setText("您好"+str_name);
int year = getIntent().getIntExtra("year",0);
int mon = getIntent().getIntExtra("mon",0);
int day = getIntent().getIntExtra("day",0);
Text_showbirth.setText("您的出生日期为:"+year+"年"+mon+"月"+day+"日");
//星座图片和星座属性选择
int [] imgarr = {R.drawable.baiyang,R.drawable.jinniu,R.drawable.shuangzi,
R.drawable.juxie,R.drawable.shizi,R.drawable.chunv,
R.drawable.tiancheng,R.drawable.tianxie,R.drawable.sheshou,
R.drawable.mojie,R.drawable.shuiping,R.drawable.shuangyu };
int [] contentaar = {R.string.白羊座,R.string.金牛座,R.string.双子座,
R.string.巨蟹座,R.string.狮子座,R.string.处女座,
R.string.天秤座,R.string.天蝎座,R.string.射手座,
R.string.摩羯座,R.string.水瓶座,R.string.双鱼座};
//设置星座
int index = findstar(mon,day);
img_star.setImageResource(imgarr[index]);
Text_showstar.setText(contentaar[index]);
//通信
Button btn;
btn = findViewById(R.id.BTN_BACK);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity2.this,MainActivity.class);
startActivity(intent);
}
});
}
private int findstar(int mon, int day)
{
int i = 0;
if(mon == 3 && day >=21 || mon == 4 && day <=19){i = 0;}
if(mon == 4 && day >=20 || mon == 5 && day <=20){i = 1;}
if(mon == 5 && day >=21 || mon == 6 && day <=21){i = 2;}
if(mon == 6 && day >=22 || mon == 7 && day <=22){i = 3;}
if(mon == 7 && day >=23 || mon == 8 && day <=22){i = 4;}
if(mon == 8 && day >=23 || mon == 9 && day <=22){i = 5;}
if(mon == 9 && day >=23 || mon == 10 && day <=23){i = 6;}
if(mon == 10 && day >=24 || mon == 11 && day <=22){i = 7;}
if(mon == 11 && day >=23 || mon == 12 && day <=21){i = 8;}
if(mon == 12 && day >=22 || mon == 1 && day <=19){i = 9;}
if(mon == 1 && day >=20 || mon == 2 && day <=18){i = 10;}
if(mon == 2 && day >=19 || mon == 3 && day <=20){i = 11;}
return i;
}
}