layout-item_info:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/sex"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/age"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView listView=(ListView)findViewById(R.id.my_lv);
List<Map<String,?>> datalist=new ArrayList<>();
for(int i=0;i<50;i++){
Map<String,String> map=new HashMap<>();
map.put("name","张三"+i);
map.put("sex",i%2==0?"男":"女");
map.put("age",10+i+"");
datalist.add(map);
}
String from[]={"name","sex","age"};
int to[]={R.id.name,R.id.sex,R.id.age};
SimpleAdapter simpleAdapter=new SimpleAdapter(this,datalist,
R.layout.item_info,from,to);
listView.setAdapter(simpleAdapter);
}
}