新增界面
以及自动生成的
界面
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);
}
});