安卓第二次作业

新增界面

?以及自动生成的在这里插入图片描述

界面
activity_home.xml

在这里插入图片描述

activity_detail10.xml

在这里插入图片描述

activity_detail11.xml

在这里插入图片描述

activity_detail12.xml

在这里插入图片描述

代码
home.java
package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SearchView;
import android.text.TextUtils;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.os.Bundle;

public class home extends AppCompatActivity {

    private String[] Strs={"See what's new in Android 12","See what's new in Android 11","See what's new in Android 10"};
    private SearchView searchView1;
    private ListView listView1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        searchView1=(SearchView)findViewById(R.id.searchView);
        listView1=(ListView)findViewById(R.id.listView);
        listView1.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, Strs));
        listView1.setTextFilterEnabled(true);

        searchView1.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                return false;
            }
            @Override
            public boolean onQueryTextChange(String newText) {
                if (!TextUtils.isEmpty(newText)){
                    listView1.setFilterText(newText);
                }else{
                    listView1.clearTextFilter();
                }
                return false;
            }
        });

    }
}
activity_home.xml
<?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:orientation="vertical"
    tools:context=".home">

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="281dp"
        android:layout_weight="1"
        app:srcCompat="@drawable/andr" />

    <androidx.appcompat.widget.SearchView
        android:id="@+id/searchView"
        android:layout_width="match_parent"
        android:layout_height="242dp"
        android:layout_weight="1"
        android:iconifiedByDefault="false"
        android:queryHint="Search" />

    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1" />
</LinearLayout>
detail12.xml
<?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="wrap_content"
    android:orientation="vertical"
    tools:context=".detail12">

    <TextView
        android:id="@+id/textView5"
        android:layout_width="match_parent"
        android:layout_height="103dp"
        android:layout_weight="1"
        android:gravity="center"
        android:text="See what's new in Android 12"
        android:textSize="36sp" />

    <ImageView
        android:id="@+id/imageView4"
        android:layout_width="match_parent"
        android:layout_height="411dp"
        android:layout_weight="1"
        app:srcCompat="@drawable/android12logo" />

    <TextView
        android:id="@+id/textView6"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Find more detail by the website below"
        android:gravity="center"
        android:textSize="30sp"/>

    <TextView
        android:id="@+id/textView7"
        android:layout_width="321dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:autoLink="web"
        android:gravity="center"
        android:layout_gravity="center"
        android:text="www.developer.android.google.cn"
        android:textSize="30sp" />
</LinearLayout>

剩下两个相似
MyAdapter新增以下代码

private Class[] jumpActivity={contactsdetail1.class,contactsdetail2.class};
holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //Toast.makeText(context, "你点击的是:" + content, Toast.LENGTH_SHORT).show();
                Intent intent=new Intent(context,jumpActivity[position]);
                context.startActivity(intent);
            }
        });
部分运行截图

在这里插入图片描述

源码地址

url

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值