⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 list4.java

📁 Google s android SDK
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*  * Copyright (C) 2007 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.google.android.samples.view;//Need the following import to get access to the app resources, since this//class is in a sub-package.import android.app.ListActivity;import android.content.Context;import android.os.Bundle;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.LinearLayout;import android.widget.TextView;/** * A list view example where the data comes from a custom ListAdapter */public class List4 extends ListActivity {    @Override    public void onCreate(Bundle icicle) {        super.onCreate(icicle);        // Use our own list adapter        setListAdapter(new SpeechListAdapter(this));    }    /**     * A sample ListAdapter that presents content from arrays of speeches and     * text.     *      */    private class SpeechListAdapter extends BaseAdapter {        public SpeechListAdapter(Context context) {            mContext = context;        }        /**         * The number of items in the list is determined by the number of speeches         * in our array.         *          * @see android.widget.ListAdapter#getCount()         */        public int getCount() {            return mTitles.length;        }        /**         * Since the data comes from an array, just returning the index is         * sufficent to get at the data. If we were using a more complex data         * structure, we would return whatever object represents one row in the         * list.         *          * @see android.widget.ListAdapter#getItem(int)         */        public Object getItem(int position) {            return position;        }        /**         * Use the array index as a unique id.         *          * @see android.widget.ListAdapter#getItemId(int)         */        public long getItemId(int position) {            return position;        }        /**         * Make a SpeechView to hold each row.         *          * @see android.widget.ListAdapter#getView(int, android.view.View,         *      android.view.ViewGroup)         */        public View getView(int position, View convertView, ViewGroup parent) {            SpeechView sv;            if (convertView == null) {                sv = new SpeechView(mContext, mTitles[position],                        mDialogue[position]);            } else {                sv = (SpeechView) convertView;                sv.setTitle(mTitles[position]);                sv.setDialogue(mDialogue[position]);            }            return sv;        }        /**         * Remember our context so we can use it when constructing views.         */        private Context mContext;                /**         * Our data, part 1.         */        private String[] mTitles =         {                "Henry IV (1)",                   "Henry V",                "Henry VIII",                       "Richard II",                "Richard III",                "Merchant of Venice",                  "Othello",                "King Lear"        };                /**         * Our data, part 2.         */        private String[] mDialogue =         {                "So shaken as we are, so wan with care," +                "Find we a time for frighted peace to pant," +                "And breathe short-winded accents of new broils" +                "To be commenced in strands afar remote." +                "No more the thirsty entrance of this soil" +                "Shall daub her lips with her own children's blood;" +                "Nor more shall trenching war channel her fields," +                "Nor bruise her flowerets with the armed hoofs" +                "Of hostile paces: those opposed eyes," +                "Which, like the meteors of a troubled heaven," +                "All of one nature, of one substance bred," +                "Did lately meet in the intestine shock" +                "And furious close of civil butchery" +                "Shall now, in mutual well-beseeming ranks," +                "March all one way and be no more opposed" +                "Against acquaintance, kindred and allies:" +                "The edge of war, like an ill-sheathed knife," +                "No more shall cut his master. Therefore, friends," +                "As far as to the sepulchre of Christ," +                "Whose soldier now, under whose blessed cross" +                "We are impressed and engaged to fight," +                "Forthwith a power of English shall we levy;" +                "Whose arms were moulded in their mothers' womb" +                "To chase these pagans in those holy fields" +                "Over whose acres walk'd those blessed feet" +                "Which fourteen hundred years ago were nail'd" +                "For our advantage on the bitter cross." +                "But this our purpose now is twelve month old," +                "And bootless 'tis to tell you we will go:" +                "Therefore we meet not now. Then let me hear" +                "Of you, my gentle cousin Westmoreland," +                "What yesternight our council did decree" +                "In forwarding this dear expedience.",                                "Hear him but reason in divinity," +                 "And all-admiring with an inward wish" +                 "You would desire the king were made a prelate:" +                 "Hear him debate of commonwealth affairs," +                 "You would say it hath been all in all his study:" +                 "List his discourse of war, and you shall hear" +                 "A fearful battle render'd you in music:" +                 "Turn him to any cause of policy," +                 "The Gordian knot of it he will unloose," +                 "Familiar as his garter: that, when he speaks," +                 "The air, a charter'd libertine, is still," +                 "And the mute wonder lurketh in men's ears," +                 "To steal his sweet and honey'd sentences;" +                 "So that the art and practic part of life" +                 "Must be the mistress to this theoric:" +                 "Which is a wonder how his grace should glean it," +                 "Since his addiction was to courses vain," +                 "His companies unletter'd, rude and shallow," +                 "His hours fill'd up with riots, banquets, sports," +                 "And never noted in him any study," +                 "Any retirement, any sequestration" +                 "From open haunts and popularity.",                "I come no more to make you laugh: things now," +

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -