android-ListView

2022-07-16 16:22:58 浏览数 (1)

代码语言:javascript复制
</RelativeLayout>


private ListView listView;

// 数据
private String[] data = { "Apple", "Banana", "Orange", "Watermelon", "Pear", "Grape", "Pineapple", "Strawberry",
"Cherry", "Mango", "Apple", "Banana", "Orange","Watermelon", "Pear", "Grape", "Pineapple", "Strawberry",
        "Cherry", "Mango" };

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test);
    listView = (ListView) findViewById(R.id.list_view);
    // 适配器
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(ActivityTest.this, android.R.layout.simple_list_item_1, data);
    listView.setAdapter(adapter);
}

0 人点赞