public class MainActivity extends AppCompatActivity { private Button bt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bt = findViewById(R.id.button);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this,mulu.class);
startActivity(intent);
}
2.
public class mulu extends AppCompatActivity {
private Button bt1; private Button bt8; String mulu[] = {“第一回 甄士隐梦幻识通灵 贾雨村风尘怀闺秀”,“第二回 贾夫人仙逝扬州城 冷子兴演说荣国府”,“第三回 贾雨村夤缘复旧职 林黛玉抛父进京都”,“第四回 薄命女偏逢薄命郎 葫芦僧乱判葫芦案”,“第五回 游幻境指迷十二钗 饮仙醪曲演红楼梦”}; private ListView listView; ArrayAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_mulu); bt1=findViewById(R.id.button7); listView = findViewById(R.id.lv); bt1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(mulu.this,MainActivity.class); startActivity(intent); } }); adapter = new ArrayAdapter(mulu.this,android.R.layout.simple_list_item_1,mulu); listView.setAdapter(adapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { String result = adapterView.getItemAtPosition(i).toString(); Toast.makeText(mulu.this,“您点击了”+result,Toast.LENGTH_SHORT).show(); if(i==0){ Intent intent = new Intent(mulu.this,neirong.class); startActivity(intent); } } 3. ublic class neirong extends AppCompatActivity { private Button bt2; private Button bt3; private TextView tx; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_neirong); bt2 = findViewById(R.id.button2); bt3 = findViewById(R.id.button3); tx = findViewById(R.id.diyizhang); try { InputStream is = getAssets().open(“hlm1.txt”); int len = is.available(); byte[] buffer = new byte[len]; is.read(buffer); String result = new String(buffer,“utf-8”); tx.setText(result); } catch (IOException e) { e.printStackTrace(); }
bt2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(neirong.this,mulu.class);
startActivity(intent);
}
});
bt3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(neirong.this,mulu.class);
startActivity(intent);
}
});
}
|