Android学习第三天--listview方式七
2013-03-10 00:27
387 查看
跟六有点不同
主xml
放置内容的xml
实体类
主java类
主xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <ListView android:id="@+id/listview1" android:layout_width="match_parent" android:layout_height="wrap_content"/> </RelativeLayout>
放置内容的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" > <ImageView android:id="@+id/iv_headid" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/tv_stunameid" android:layout_width="wrap_content" android:layout_height="match_parent" /> <TextView android:id="@+id/tv_stutelephoneid" android:layout_width="wrap_content" android:layout_height="match_parent" /> </LinearLayout>
实体类
package cn.core.entity; import java.util.HashMap; import java.util.Map; public class Students { private Integer stuId; private String stuName; private String stuTelephone; private Map<String,String> map; private Integer stuHead; public Students() { super(); } public Students(Integer stuId, String stuName, String stuTelephone, Integer stuHead) { super(); this.stuId = stuId; this.stuName = stuName; this.stuTelephone = stuTelephone; this.stuHead = stuHead; } public Map<String,String> getMap() { map =new HashMap<String,String>(); map.put("stuHead", String.valueOf(stuHead)); map.put("stuName", stuName); map.put("stuTelephone", stuTelephone); return map; } public Integer getStuId() { return stuId; } public void setStuId(Integer stuId) { this.stuId = stuId; } public String getStuName() { return stuName; } public void setStuName(String stuName) { this.stuName = stuName; } public String getStuTelephone() { return stuTelephone; } public void setStuTelephone(String stuTelephone) { this.stuTelephone = stuTelephone; } }
主java类
import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import cn.core.entity.Students; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemLongClickListener; import android.widget.ArrayAdapter; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.SimpleAdapter; public class MainActivity extends Activity { private static final String TAG="LAOGUO"; List<Map<String,String>> list= null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ListView listView=(ListView)findViewById(R.id.listview1); Students stu1=new Students(1,"是","13860483016",R.drawable.head1); Students stu2=new Students(2,"的飞","15959440256",R.drawable.head2); list=new ArrayList<Map<String,String>>(); list.add(stu1.getMap()); list.add(stu2.getMap()); ListAdapter listAdapter = new SimpleAdapter(this, list, R.layout.activity_lv, new String[]{"stuHead","stuName","stuTelephone"}, new int[]{R.id.iv_headid,R.id.tv_stunameid,R.id.tv_stutelephoneid}); listView.setAdapter(listAdapter); listView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int position, long arg3) { String str=arg0.getItemAtPosition(position).toString(); String tel=(String)list.get(position).get("stuTelephone"); Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+tel)); MainActivity.this.startActivity(intent); return false; } }); } }
相关文章推荐
- Android学习第三天--listview方式一
- Android学习第三天--listview方式四
- Android学习第三天--listview方式二
- Android学习第三天--listview方式五
- Android学习第三天--listview方式三
- Android学习第三天--listview方式六
- android学习记录3(数据存储的方式:sqlite、sp、存文件。listview简单使用)
- Android学习 —— 多种适配器方式实现ListView
- Android学习 —— 多种适配器方式实现ListView
- Android学习备忘018——android 三种定位方式
- Android学习之Http使用Post方式进行数据提交
- Android学习 —— 数据的存储与访问方式一: 文件存取
- 【Android学习】列表(ListView、RecyclerView)和adapter
- Android学习之按钮单击事件及监听器的5实现方式
- android 多线程实现方式、并发与同步学习总结
- 【Android进阶学习】底部Tab的两种实现方式
- Android ListView两种长按弹出菜单方式
- Spring学习第三天——Spring MVC,使用注解方式,intellij的代码说明,ajax,文件的上传下载
- Android之ListView原理学习与优化总结
- 【Android学习】XML文本的三种解析方式(通过搭建本地的Web项目提供XML文件)