简单Adapter
来源:互联网 发布:mysql忘记密码怎么办 编辑:程序博客网 时间:2024/05/16 01:19
简单Adapter
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class FirstActivity extends Activity {
private ListView myListView;
//to define a array to set the data
String[] listData = { "Exit this way", "Far away from home",
"from sarah with love", "God is a girl" };
@Override
protected void onCreate(Bundle savedInstanceState) {
//and there i define the list view to get the data
super.onCreate(savedInstanceState);
setContentView(R.layout.first_main);
//to get the listview
myListView = (ListView) findViewById(R.id.listview);
setTitle("listview 示列 ");
First_initData();
}
private void First_initData() {
//实例化一个数组 adapter(arrayadapter)
//三个参数,this表示当前引用上下文,第二个参数利用条目显示的布局
//这里调用了系统自带的布局,第三个参数,绑定显示的数据 传入数组
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, listData);
//绑定 adapter
myListView.setAdapter(adapter);
//添加点击事件
myListView.setOnItemClickListener( new OnItemClickListener() {
//adapter 绑定的 adapter
//v 条目显示的内容
//position v 对应的位置
//id 条目的id
@Override
public void onItemClick(AdapterView<?> adapter, View v, int position, long id) {
//显示一句
new_Toast(v + "");
}
});
}
public void new_Toast(String str) {
//这里我们把 toast 封装一下
Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/mybut"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="启动第二个Activity程序" />
<ListView
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="启动第二个Activity程序" />
</LinearLayout>
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class FirstActivity extends Activity {
private ListView myListView;
//to define a array to set the data
String[] listData = { "Exit this way", "Far away from home",
"from sarah with love", "God is a girl" };
@Override
protected void onCreate(Bundle savedInstanceState) {
//and there i define the list view to get the data
super.onCreate(savedInstanceState);
setContentView(R.layout.first_main);
//to get the listview
myListView = (ListView) findViewById(R.id.listview);
setTitle("listview 示列 ");
First_initData();
}
private void First_initData() {
//实例化一个数组 adapter(arrayadapter)
//三个参数,this表示当前引用上下文,第二个参数利用条目显示的布局
//这里调用了系统自带的布局,第三个参数,绑定显示的数据 传入数组
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, listData);
//绑定 adapter
myListView.setAdapter(adapter);
//添加点击事件
myListView.setOnItemClickListener( new OnItemClickListener() {
//adapter 绑定的 adapter
//v 条目显示的内容
//position v 对应的位置
//id 条目的id
@Override
public void onItemClick(AdapterView<?> adapter, View v, int position, long id) {
//显示一句
new_Toast(v + "");
}
});
}
public void new_Toast(String str) {
//这里我们把 toast 封装一下
Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/mybut"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="启动第二个Activity程序" />
<ListView
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="启动第二个Activity程序" />
</LinearLayout>
0 0
- 简单Adapter
- Pattern: Adapter 简单实现
- Adapter简单用法
- Adapter简单使用步骤
- Adapter的简单封装
- RecyclerView Adapter简单封装
- 简单好用的Adapter
- 简单好用的Adapter
- android 简单的adapter封装
- [简单实用系列] 通用adapter
- Recyclerview Adapter 的简单封装
- RecyclerView.Adapter 的简单封装
- 简单封装RecyclerView的Adapter
- android RecycleView Adapter简单封装
- 简单的Adapter万能适配器
- Android Adapter的简单封装
- 适配器(Adapter)-通俗简单的讲解
- Android adapter更简单的使用方法
- Delphi快捷键
- 2.2016年 物电学院 电气工程及其自动化专业 辛雅松 15050341033
- Android动作广播类别消息类型
- NGUI 层次
- ipa文件重新签名的方法
- 简单Adapter
- 最小边覆盖&最小路径覆盖
- 最长公共子序列 —— NYOJ 36
- 10013---SpringMVC与Struts2区别与比较总结
- java函数返回类型
- css中字体的设置
- iOS9 HTTP 不能正常使用的解决办法
- mongodb语法
- 3.2016年 物电学院 电气工程及其自动化专业 辛雅松 15050341033