• 安卓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;
        }
    }
  • 相关阅读:
    CentOS 下安装apt-get
    Centos 6.5升级到Git2.1.2的步骤
    JAVA常识积累
    Android网络编程概述
    解读ClassLoader
    android ndk调用OpenGL 实现纹理贴图Texture
    android Bind机制(二)
    Android Binder机制原理(史上最强理解,没有之一)(转)
    NDK常见问题
    根因分析初探:一种报警聚类算法在业务系统的落地实施
  • 原文地址:https://www.cnblogs.com/txwtech/p/15911476.html
Copyright © 2020-2023  润新知