安卓学生练手简易项目:
四大名著的点击显示
第一个Activity:
<ImageView
android:id="@+id/img"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_gravity="center"
android:src="@drawable/x"/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/gp"
>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/x"
android:text="西游记"
android:textSize="30sp"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/s"
android:text="水浒传"
android:textSize="30sp"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/sg"
android:text="三国演义"
android:textSize="30sp"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/h"
android:text="红楼梦"
android:textSize="30sp"/>
</RadioGroup>
<Button
android:id="@+id/bt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="点击查看详细信息"
android:textSize="30sp"/>
第一个JAVA代码部分:
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private ImageView img;
private RadioGroup rg;
private RadioButton x,h,s,sg;
private Button bt;
String classic;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
img = findViewById(R.id.img);
rg = findViewById(R.id.gp);
x = findViewById(R.id.x);
h = findViewById(R.id.h);
s = findViewById(R.id.s);
sg = findViewById(R.id.sg);
bt = findViewById(R.id.bt);
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
switch (i){
case R.id.x:
img.setImageResource(R.drawable.x);classic = "西游记";
Toast.makeText(MainActivity.this,classic,Toast.LENGTH_LONG).show();
break;
case R.id.s:
img.setImageResource(R.drawable.s);classic = "水浒传";
Toast.makeText(MainActivity.this,classic,Toast.LENGTH_LONG).show();
break;
case R.id.h:img.setImageResource(R.drawable.h);classic = "红楼梦";
Toast.makeText(MainActivity.this,classic,Toast.LENGTH_LONG).show();
break;
case R.id.sg:
img.setImageResource(R.drawable.sg);classic = "三国演义 ";
Toast.makeText(MainActivity.this,classic,Toast.LENGTH_LONG).show();
break;
}
}
});
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent= new Intent(MainActivity.this,Main2Activity.class);
intent.putExtra("book",classic);
startActivity(intent);
}
});
}
}
第二个Activity:
<?xml version="1.0" encoding="utf-8"?><ImageView
android:id="@+id/img"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_gravity="center"
android:src="@drawable/x"/>
<TextView
android:id="@+id/te"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="25sp"
android:layout_marginTop="30sp"
android:text="示例文本"/>
第二个JAVA代码部分:
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
public class Main2Activity extends AppCompatActivity {
private TextView te;
private ImageView img;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
img = findViewById(R.id.img);
te = findViewById(R.id.te);
Intent intent = getIntent();
String getbook = intent.getStringExtra("book");
System.out.println(getbook);
switch (getbook){
case "西游记" :
img.setImageResource(R.drawable.x);
te.setText("《西游记》是中国古代第一部浪漫主义章回体长篇神魔小说。 [54] 现存明刊百回本《西游记》均无作者署名,作者是明代吴承恩。\n" +
"全书主要描写了孙悟空出世及大闹天宫后,遇见了唐僧、猪八戒、沙僧和白龙马,西行取经,\n" +
"一路上历经艰险,降妖除魔,经历了九九八十一难,终于到达西天见到如来佛祖,\n" +
"最终五圣成真的故事。该小说以“玄奘取经”这一历史事件为蓝本,经作者的艺术加工,深刻地描绘出明代百姓的社会生活状况。");
break;
case "水浒传" :
img.setImageResource(R.drawable.s);
te.setText("《水浒传》是元末明初施耐庵(现存刊本署名大多有施耐庵、罗贯中两人中的一人,或两人皆有)编著的章回体长篇小说。\n" +
"全书通过描写梁山好汉反抗欺压、水泊梁山壮大和受宋朝招安,以及受招安后为宋朝征战,最终消亡的宏大故事,艺术地反映了中国历史上宋江起义从发生、\n" +
"发展直至失败的全过程,深刻揭示了起义的社会根源,满腔热情地歌颂了起义英雄的反抗斗争和他们的社会理想,也具体揭示了起义失败的内在历史原因。\n");
break;
case "三国演义" :
img.setImageResource(R.drawable.sg);
te.setText("《三国演义》(全名为《三国志通俗演义》,又称《三国志演义》)是元末明初小说家罗贯中根据陈寿《三国志》和裴松之注解以及民间三国故事传\n" +
"说经过艺术加工创作而成的长篇章回体历史演义小说,与《西游记》《水浒传》《红楼梦》并称为中国古典四大名著。该作品成书后有嘉靖壬午本等多个版本传\n" +
"于世,到了明末清初,毛宗岗对《三国演义》整顿回目、修正文辞、改换诗文,该版本也成为诸多版本中水平最高、流传最广的版本。");
break;
case "红楼梦" :
img.setImageResource(R.drawable.h);
te.setText("《红楼梦》,中国古代章回体长篇小说,中国古典四大名著之一,通行本共120回,一般认为前80回是清代作家曹雪芹所著,后40回作者为无名氏,整理者为程伟元、高鹗。小说以贾、史、王、薛四大家族的兴衰为背景,以富贵公子贾宝玉为视角,以贾宝玉与林黛玉、薛宝钗的爱情婚姻悲剧为主线,描绘了一些举止见识出于须眉之上的闺阁佳人的人生百态,\n" +
"展现了真正的人性美和悲剧美,可以说是一部从各个角度展现女性美以及中国古代社会世态百相的史诗性著作。\n");
break;
}
}
}
结束.
967




被折叠的 条评论
为什么被折叠?



