/storage/emulated/0/AppProjects/bijj/app/src/main/res/layout/ activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="@+id/srk"
android:layout_width="320dp"
android:layout_height="wrap_content"
/>
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="-50dp"
android:src="@mipmap/fdj"
/>
</LinearLayout>
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
/storage/emulated/0/AppProjects/bijj/app/src/main/res/layout/ main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/image"
android:layout_width="50dp"
android:layout_height="50dp"
/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
/storage/emulated/0/AppProjects/bijj/app/src/main/java/com/mycompany/myapp/ MainActivity.java
package com.mycompany.myapp;
import android.app.Activity;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.*;
import java.util.*;
import android.view.*;
public class MainActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int[] imageid=new int[]{R.drawable.tp1,R.drawable.tp2,R.drawable.tp3,
R.drawable.tp4,R.drawable.tp5,R.drawable.tp6,
R.drawable.tp7,R.drawable.tp8,R.drawable.tp9};
String[] title=new String[]{"六一","橙二","张三","李四","王五",
"赵柳","孙七","周八","吴九"};
List<Map<String,Object>> listitem=new ArrayList<Map<String,Object>>();
for (int i=0;i < imageid.length;i++)
{
Map<String,Object> map=new HashMap<String,Object>();
map.put("image",imageid[i]);
map.put("name",title[i]);
listitem.add(map);
}
SimpleAdapter adapter=new SimpleAdapter(this,listitem,R.layout.main,new String[]{"name","image"},
new int[]{R.id.title,R.id.image});
ListView listView=(ListView)findViewById(R.id.listview);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view,int position,long id){
Map<String,Object> map=(Map<String,Object>)parent.getItemAtPosition(position);
Toast.makeText(MainActivity.this,map.get("name").toString(),Toast.LENGTH_LONG).show();
}
});
}
}
放图片路径 /storage/emulated/0/AppProjects/bijj/app/src/main/res/drawable 放9张图片 tp1.png tp2.png tp3.png tp4.png tp5.png …
|