Android07-高级控件-ListView
来源:互联网 发布:游戏开发行业前景知乎 编辑:程序博客网 时间:2024/05/21 01:42
ListView:先在XML写一个高级控件ListView
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ListView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/lv_list_names" ></ListView></LinearLayout>
然后去Activity写如下代码:
package com.zking.g160628_android07_widgetplus;import android.os.Bundle;import android.support.annotation.Nullable;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.AdapterView;import android.widget.ArrayAdapter;import android.widget.ListView;import android.widget.Toast;import java.util.ArrayList;import java.util.List;/** * @author Zking-Snail * @time 2017/6/8 11:18 * @Version ${REV} */public class ListActivity extends AppCompatActivity { private ListView lv_list_names; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list); lv_list_names = (ListView) findViewById(R.id.lv_list_names); final List<String> names=new ArrayList<>(); for (int i = 0; i <100; i++) { names.add("张"+i); } ArrayAdapter adapter=new ArrayAdapter(this,android.R.layout.simple_list_item_1,names); lv_list_names.setAdapter(adapter); //给ListView设置点击事件 lv_list_names.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { Toast.makeText(ListActivity.this, names.get(i), Toast.LENGTH_SHORT).show(); } }); }}
阅读全文
0 0
- Android07-高级控件-ListView
- Android07
- Android07
- ListView控件高级应用
- 高级控件Listview
- android高级控件ListView
- ListView android高级控件
- android高级控件-ListView
- Android高级控件之ListView
- Windows应用程序高级控件之ListView控件
- Android高级UI控件—ListView
- Android UI高级控件中的ListView
- 高级控件之列表视图(ListView)
- Android—高级控件(二)ListView
- Android高级控件之ExpandableListView可以展开的listview
- Android高级控件ListView和GridView原理分析
- Android高级控件系列之ListView的用法
- 8.高级控件(二)之ListView优化
- 瑞士轮 洛谷1309 排序
- Sturts2和Hibernate整合可能会出现的错误
- 进程和线程的区别
- 一些linux命令
- 关于Windows7如何禁止程序自启动
- Android07-高级控件-ListView
- Oracle12C--参数模式(四十一)
- 动态方法ByTageName()
- Oracle12C--子程序的嵌套(四十二)
- 黑化的牛牛
- hdu 1045 贪心算法、DFS、枚举回溯&二分图
- Android_ViewPage_Fragment_模仿微信界面
- 基于 CoreText 的排版引擎:基础
- flume1.6.0安装