您好,欢迎访问成都祈钰瑶科技有限公司!

全国咨询热线

18982081108
✕

成都网站建设公司,成都网站UI设计,成都网站安全维护,成都网站内容优化服务

SimpleAdapter之最简单的适配器

package com.example.testsimpleadapter;
public class MainActivity extends Activity implements OnItemClickListener{
private ListView listView;
private Button btn;
private List<Map<String, Object>> contents = new ArrayList<Map<String, Object>>();;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.listView1);
listView.setOnItemClickListener(this);
initAdapter();
}
private void initAdapter(){

contents = new ArrayList<Map<String, Object>>();
for (int i = 0; i < 20; i++) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("p_w_picpath", R.drawable.ic_launcher);
map.put("text_title", "Test Title");
map.put("text_msg", "msg");
contents.add(map);
}
SimpleAdapter adapter = new SimpleAdapter(this,
(List<Map<String, Object>>) contents, R.layout.item,
new String[] { "p_w_picpath", "text_title", "text_msg"}, new int[] {
R.id.p_w_picpath, R.id.text_title, R.id.text_msg});
listView.setAdapter(adapter);
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Toast.makeText(this, arg2 + "", Toast.LENGTH_SHORT).show();
}
}

//item.xml

十载的古城网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。全网营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整古城建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联从事“古城网站设计”,“古城网站推广”以来,每个客户项目都认真落实执行。

<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"
    android:descendantFocusability="blocksDescendants" 
    tools:context=".MainActivity" >
    <ImageView
        android:id="@+id/p_w_picpath"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="36dp"
        android:layout_marginTop="17dp"
        android:src="@drawable/ic_launcher" />
    <TextView
        android:id="@+id/text_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/p_w_picpath"
        android:layout_toRightOf="@+id/p_w_picpath"
        android:text="Title Text"
        android:gravity="center"
        android:textAppearance="?android:attr/textAppearanceLarge" />
    <TextView
        android:id="@+id/text_msg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/p_w_picpath"
        android:layout_alignLeft="@+id/text_title"
        android:layout_alignParentRight="true"
        android:gravity="center"
        android:text="msg Text" />
</RelativeLayout>

//布局文件里只有一个list