Android学习第三天--listview方式二

主xml中

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:id="@+id/listview1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>

一样的array.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="info">
        <item>1</item>
        <item>l1</item>
        <item>3</item>
        <item>l33</item>
        <item>l123</item>
        <item>33是</item>
        <item>是否</item>
        <item>水电费</item>
        <item>电视广告</item>
            <item>时代复分</item>
        <item>温热污染</item>
        <item>啊啊</item>
    </string-array>    
</resources>

java中

public class MainActivity extends Activity {

    ListView listView =null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        listView=(ListView)findViewById(R.id.listview1);
        
        ArrayAdapter arrayAdapter = ArrayAdapter.createFromResource(this, R.array.info, android.R.layout.simple_list_item_1);
        listView.setAdapter(arrayAdapter);
    
        
    }


}

 

 

posted @ 2013-03-09 17:21  小三小山  阅读(201)  评论(0编辑  收藏  举报