安卓app_sl3_18_19列表视图

 

复制代码
<!-- sl3_19 -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.sl3_18.MainActivity" >

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:divider="@drawable/greendivider"
        android:dividerHeight="3dp"
        android:footerDividersEnabled="false"
        android:headerDividersEnabled="false"
        android:layout_alignParentTop="true" >
    </ListView>

</RelativeLayout>
复制代码
复制代码
<!-- array.xml -->
<resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="android:Theme.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>
    <string-array 
        name="ctype">
        <item>情景模式</item>
        <item>主题模式</item>
        <item>手机</item>
        <item>程序管理</item>
        <item>通话设置</item>
        <item>连接功能</item>
    </string-array>

</resources>
复制代码
复制代码
package com.example.sl3_18;
//与sl3_19
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final ListView listView=(ListView)findViewById(R.id.listView1);
        listView.addHeaderView(line());
        ArrayAdapter<CharSequence> adapter= ArrayAdapter.createFromResource(this, R.array.ctype, android.R.layout.simple_list_item_checked);
        listView.setAdapter(adapter);
        listView.addFooterView(line());
        listView.setOnItemClickListener(new OnItemClickListener(){

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                // TODO 自动生成的方法存根
                String result=parent.getItemAtPosition(position).toString();
                Toast.makeText(MainActivity.this, result, Toast.LENGTH_SHORT).show();
                
            }
            
        });
        
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
    private View line()
    {
        ImageView image=new ImageView(this);
        image.setImageResource(R.drawable.line1);
        return image;
    }
}
复制代码

 

posted @   txwtech  阅读(31)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
历史上的今天:
2020-02-18 cb25a_c++_函数对象简介
2020-02-18 cb24a_c++_STL算法简介
2020-02-18 cb23a_c++_标准模板库STL_set_multiset_关联容器
2020-02-18 cb22a_c++_标准模板库_STL_map_multimap红黑树(数据结构)关联容器
点击右上角即可分享
微信分享提示