android之使用ListView实现多菜单功能
我们知道很多软件都有设置菜单项如微信墨迹天气等的设置界面。当设置里有很多选项这时我们可以选择使用ListView实现。
布局文件如下:
[html] <?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"
android:background="@drawable/splash_background"
>
<ListView android:id="@+id/more_List"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="@drawable/list_bottom_line"
android:listSelector="#00000000"
android:cacheColorHint="#00000000">
</ListView>
</LinearLayout>
<?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"
android:background="@drawable/splash_background"
>
<ListView android:id="@+id/more_List"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="@drawable/list_bottom_line"
android:listSelector="#00000000"
android:cacheColorHint="#00000000">
</ListView>
</LinearLayout>很简单只有一个ListView
item的布局:
[html] <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dip"
android:background="@drawable/list_item"
>
<ImageView android:id="@+id/item_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView android:id="@+id/more_item_text"
android:layout_marginLeft="10dip"
android:textSize="20dip"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView android:id="@+id/item_image"
android:layout_marginTop="5dip"
android:layout_marginLeft="10dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/易做图"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dip"
android:background="@drawable/list_item"
>
<ImageView android:id="@+id/item_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView android:id="@+id/more_item_text"
android:layout_marginLeft="10dip"
android:textSize="20dip"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView android:id="@+id/item_image"
android:layout_marginTop="5dip"
android:layout_marginLeft="10dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/易做图"
/>
</LinearLayout>设置成水平布局,一次是图标,文字说明,箭头图标
主要代码如下:
[java] package com.cloay.news;
import com.cloay.news.bean.MoreAdapter;
import com.cloay.news.service.MainService;
import com.cloay.news.util.AlertDlgUtil;
import com.waps.AppConnect;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
/**
* 更多界面包含帮助,关于等。
* @author Cloay
* 2012-3-3
* 下午09:45:12
*/
public class MoreActivity extends NewsReaderActivity {
private ListView moreList;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.more);
MainService.allActivity.add(this);
moreList = (ListView) findViewById(R.id.more_List);
MoreAdapter adapter = new MoreAdapter(this);
moreList.setAdapter(adapter);
moreList.setOnItemClickListener(new OnItemClickListener() { //为每一个item设置相应的响应
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position
补充:移动开发 , Android ,