您的位置:首页 > 移动开发 > Android开发

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

2013-03-09 17:11 295 查看
第一种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:entries="@array/info"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

</LinearLayout>


在res下的values下添加下面的文件

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="info">
<item>test1</item>
<item>test1</item>
<item>test1</item>
<item>test1</item>
<item>test1</item>
<item>test1</item>
<item>test1</item>
<item>ltest1n</item>
<item>test1</item>
<item>test1</item>
<item>test1</item>
<item>test1</item>
</string-array>
</resources>


主java文件中

package cn.core.test;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

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);

listView.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,long arg3) {

System.out.println(arg0.getItemAtPosition(position).toString());
}
});

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: