ShowListActivity extends ListActivity

res\layout\user_info.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" >

    <TextView
        android:id="@+id/user_name"
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"        
        />

    <TextView
        android:id="@+id/user_address"
        android:layout_weight="2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:gravity="right"       
        />

</LinearLayout>

res\layout\activity_show_list.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="${relativePackage}.${activityClass}" >

    <LinearLayout android:id="@+id/ListLinearLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <ListView  android:id="@id/android:list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scrollbars="vertical" />
    
    </LinearLayout>
    
</LinearLayout>
package com.skex.listsqllite;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.SimpleAdapter;

public class ShowListActivity extends ListActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_list);
        
        Intent intent=getIntent();
        Bundle bundle=intent.getBundleExtra("data");
        
        ArrayList<String> userNameList=bundle.getStringArrayList("user_name_array");
        ArrayList<String> userAddressList=bundle.getStringArrayList("user_address_array");
        String strTips=String.format("%d, %d",userNameList.size(),userAddressList.size());
        this.setTitle(strTips);
        
        ArrayList<HashMap<String,String>> list =new ArrayList<HashMap<String,String>>();
        for(int i=0;i<userNameList.size();i++){
            HashMap<String,String> map=new HashMap<String,String>();
            map.put("user_name", userNameList.get(i));
            map.put("user_address", userAddressList.get(i));
            list.add(map);
        }
        //
        SimpleAdapter listAdapter=new SimpleAdapter(this,list, 
                R.layout.user_info, 
                new String[]{"user_name","user_address"}, 
                new int[]{R.id.user_name,R.id.user_address}
                );
        setListAdapter(listAdapter);    
        
    }
}

 

posted @ 2018-03-19 22:49  sky20080101  阅读(75)  评论(0)    收藏  举报