Android ListView应用
来源:互联网 发布:caffe translator 编辑:程序博客网 时间:2024/06/10 06:17
一.应用Android原本就有的ListView
1.其可以在Activity和Fragment中应用。
在layout中布局:
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="7"> <ListView android:paddingTop="2dp" android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@id/android:list" ></ListView> </LinearLayout>
2.在相应的Fragment.java中对应代码:
注意这里的Fragment继承了ListFragment
public class WrongFragment extends ListFragment { private List<Map<String,String>> data=new ArrayList<Map<String,String>>(); // TODO: Rename parameter arguments, choose names that match @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View wrongView= inflater.inflate(R.layout.fragment_wrong, container, false); Map<String,String> map1=new HashMap<String,String>(); map1.put("wrongType","职业道德与理论"); data.add(map1); Map<String,String> map2=new HashMap<String,String>(); map2.put("wrongType", "专业能力考核"); data.add(map2); setListAdapter(new SimpleAdapter(getActivity(),data,android.R.layout.simple_list_item_1, new String[]{"wrongType"}, new int[]{android.R.id.text1} //名字在text1上显示 ));
3.在WrongFragment对应的Activity中对应代码:
protected void onCreate(Bundle savedInstanceState) { clickListViewItem(); } public void clickListViewItem(){ final ListView wrongList=(ListView)findViewById(android.R.id.list); wrongList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if(oldView!=null){ oldView.setBackgroundResource(0); } oldView=view; view.setBackgroundResource(R.drawable.bg_tabselect); Intent intent = new Intent(); intent.setClass(MainActivity.this,WrongActivity.class); Map<String,String> map=(Map<String,String>)wrongList.getItemAtPosition(position); Bundle bundle=new Bundle(); bundle.putString("wrongType",map.get("wrongType")); intent.putExtras(bundle); startActivity(intent); } }); }写好后就转到对应的WrongActivity中去啦
效果如下:
二.自己定义Adapter -----ListView
这里我写几个步骤:
1.在XML不居中定义一个ListView
2.创建list_item.xml用来设置ListView中每个Item的布局。
3,.在对应的Activity中封装显示数据
4.自定义适配器,需继承BaseAdapter
5.获取对应的ListView,设置适配器
具体内容请关联:http://blog.csdn.net/hellohm/article/details/12356649
http://blog.csdn.net/hellohm/article/details/12685371
这里写得很详细,我就没有必要再列举啦。
2.1也是一样需要在Layout.xml中布局一个ListView,区别在于这个ListView的android:id是自己定义的。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" ><TextViewandroid:id="@+id/welcome2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/urlcheck" /><ListView android:layout_height="wrap_content" android:id="@+id/jsonlistView" android:layout_width="fill_parent"></ListView></LinearLayout>
0 0
- Android中ListView应用
- Android ListView应用
- Android ListView应用
- Android中的ListView的应用
- Android基础教程(十)之-------ListView的应用
- android listview的简单应用步骤
- android ListView 应用及事件监听方法
- Android应用–必须知道的ListView
- Android之TabHost与ListView结合应用
- Android基础教程(十)之-------ListView的应用
- android 笔记——listView应用
- android应用中ListView的使用方法
- Android应用开发-ScrollView嵌套ListView
- android 笔记——listView应用
- Android listView的应用以及Activity跳转
- Android 5.0 CardView+ListView 卡片布局应用
- Android中ListView的具体应用
- ListView应用
- Kohana配置干净的URL
- java程序员成长路线
- 如何在Web项目中的service业务层获取项目根路劲
- Python正则表达式——去掉数字中的逗号
- 企业级应用程序开发的技术概览
- Android ListView应用
- SOAP协议
- 用ASP.NET构建完整E-mail发送系统
- opencv2.2.0源代码(include文件)分析(3)--上部分
- tcltk控制chariot进行测试,并将批量数据输出成excel
- 设计模式浅谈--单例模式
- 115个Java面试题和答案——终极列表(上)
- android:shape的使用
- 提高IIS的安全性