欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

運用WindowManager,當滾動列表時顯示一個類似T

系統 1837 0
android API demo中的實例,滾動列表時顯示一個類似Toast的提示,用于表示滾動到了不同的區域了。

運用WindowManager,當滾動列表時顯示一個類似Toast的提示(android demo)

    
public class List9 extends ListActivity implements ListView.OnScrollListener {

    private final class RemoveWindow implements Runnable {
        public void run() {
            removeWindow();
        }
    }

    private RemoveWindow mRemoveWindow = new RemoveWindow();
    Handler mHandler = new Handler();
    private WindowManager mWindowManager;
    private TextView mDialogText;
    private boolean mShowing;
    private boolean mReady;
    private char mPrevLetter = Character.MIN_VALUE;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mWindowManager = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
        
        // Use an existing ListAdapter that will map an array
        // of strings to TextViews
        setListAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, mStrings));
        
        getListView().setOnScrollListener(this);
        
        LayoutInflater inflate = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        
        mDialogText = (TextView) inflate.inflate(R.layout.list_position, null);
        mDialogText.setVisibility(View.INVISIBLE);
        
        mHandler.post(new Runnable() {

            public void run() {
                mReady = true;
                WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
                        LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
                        WindowManager.LayoutParams.TYPE_APPLICATION,
                        WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
                                | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                        PixelFormat.TRANSLUCENT);
                mWindowManager.addView(mDialogText, lp);
            }});
    }
    
    @Override
    protected void onResume() {
        super.onResume();
        mReady = true;
    }

    
    @Override
    protected void onPause() {
        super.onPause();
        removeWindow();
        mReady = false;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mWindowManager.removeView(mDialogText);
        mReady = false;
    }

    
   
    
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        int lastItem = firstVisibleItem + visibleItemCount - 1;
        if (mReady) {
            char firstLetter = mStrings[firstVisibleItem].charAt(0);
            
            if (!mShowing && firstLetter != mPrevLetter) {

                mShowing = true;
                mDialogText.setVisibility(View.VISIBLE);
               

            }
            mDialogText.setText(((Character)firstLetter).toString());
            mHandler.removeCallbacks(mRemoveWindow);
            mHandler.postDelayed(mRemoveWindow, 3000);
            mPrevLetter = firstLetter;
        }
    }
    

    public void onScrollStateChanged(AbsListView view, int scrollState) {
    }
    
    
    private void removeWindow() {
        if (mShowing) {
            mShowing = false;
            mDialogText.setVisibility(View.INVISIBLE);
        }
    }

    private String[] mStrings = {
            "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam",
            .......
            "Aubisque Pyrenees", "Autun", "Avaxtskyr", "Baby Swiss", "Babybel",
            "Baguette Laonnaise", "Bakers", "Baladi", "Balaton", "Bandal",
            .......
            "Button (Innes)", "Buxton Blue", "Cabecou", "Caboc", "Cabrales",
            "Cachaille", "Caciocavallo", "Caciotta", "Caerphilly",
            .......
    }
}

  

list_position.xml
    
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:textSize="50sp"
    android:textColor="#99FFFFFF"
    android:background="#BB000000"
    android:minWidth="70dip"
    android:maxWidth="70dip"
    android:padding="10dip"
    android:gravity="center"
/>

  


CollapsedListView可折疊的ListView:
運用WindowManager,當滾動列表時顯示一個類似Toast的提示(android demo)
    
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.ListView;
import android.widget.TextView;


/**
 * A list view example where the 
 * data comes from a custom
 * ListAdapter
 */
public class List6 extends ListActivity 
{
    
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        
        // Use our own list adapter
        setListAdapter(new SpeechListAdapter(this));
    }
        
    
    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) 
    {    
       ((SpeechListAdapter)getListAdapter()).toggle(position);
    }
    
    /**
     * 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], mExpanded[position]);
            } else {
                sv = (SpeechView)convertView;
                sv.setTitle(mTitles[position]);
                sv.setDialogue(mDialogue[position]);
                sv.setExpanded(mExpanded[position]);
            }
            
            return sv;
        }

        public void toggle(int position) {
            mExpanded[position] = !mExpanded[position];
            notifyDataSetChanged();
        }
        
        /**
         * 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," +
               ......
                "In forwarding this dear expedience.",
                
                "Hear him but reason in divinity," + 
              ......
                "From open haunts and popularity.",

                "I come no more to make you laugh: things now," +
                ......
                "A man may weep upon his wedding-day.",
                
                "First, heaven be the record to my speech!" + 
               ......
                "What my tongue speaks my right drawn sword may prove.",
                
                "Now is the winter of our discontent" + 
               ......
                "Clarence comes.",
                
                "To bait fish withal: if it will feed nothing else," + 
              ......
                "will better the instruction.",
                
                "Virtue! a fig! 'tis in ourselves that we are thus" + 
               ......
                "you call love to be a sect or scion.",

                "Blow, winds, and crack your cheeks! rage! blow!" + 
                ......
                "That make ingrateful man!"
        };
        
        /**
         * Our data, part 3.
         */
        private boolean[] mExpanded = 
        {
                false,
                false,
                false,
                false,
                false,
                false,
                false,
                false   
        };
    }
    
    /**
     * We will use a SpeechView to display each speech. It's just a LinearLayout
     * with two text fields.
     *
     */
    private class SpeechView extends LinearLayout {
        public SpeechView(Context context, String title, String dialogue, boolean expanded) {
            super(context);
            
            this.setOrientation(VERTICAL);
            
            // Here we build the child views in code. They could also have
            // been specified in an XML file.
            
            mTitle = new TextView(context);
            mTitle.setText(title);
            addView(mTitle, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
            
            mDialogue = new TextView(context);
            mDialogue.setText(dialogue);
            addView(mDialogue, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
            
            mDialogue.setVisibility(expanded ? VISIBLE : GONE);
        }
        
        /**
         * Convenience method to set the title of a SpeechView
         */
        public void setTitle(String title) {
            mTitle.setText(title);
        }
        
        /**
         * Convenience method to set the dialogue of a SpeechView
         */
        public void setDialogue(String words) {
            mDialogue.setText(words);
        }
        
        /**
         * Convenience method to expand or hide the dialogue
         */
        public void setExpanded(boolean expanded) {
            mDialogue.setVisibility(expanded ? VISIBLE : GONE);
        }
        
        private TextView mTitle;
        private TextView mDialogue;
    }
}

  


從下往上添加item的ListView:
運用WindowManager,當滾動列表時顯示一個類似Toast的提示(android demo)
    
import android.app.ListActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;

import com.example.android.apis.R;

import java.util.ArrayList;

/**
 * Demonstrates the using a list view in transcript mode
 *
 */
public class List12 extends ListActivity implements OnClickListener, OnKeyListener {

    private EditText mUserText;
    
    private ArrayAdapter<String> mAdapter;
    
    private ArrayList<String> mStrings = new ArrayList<String>();
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.list_12);
        
        mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mStrings);
        
        setListAdapter(mAdapter);
        
        mUserText = (EditText) findViewById(R.id.userText);

        mUserText.setOnClickListener(this);
        mUserText.setOnKeyListener(this);
    }

    public void onClick(View v) {
        sendText();
    }

    private void sendText() {
        String text = mUserText.getText().toString();
        mAdapter.add(text);
        mUserText.setText(null);
    }

    public boolean onKey(View v, int keyCode, KeyEvent event) {
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_CENTER:
                case KeyEvent.KEYCODE_ENTER:
                    sendText();
                    return true;
            }
        }
        return false;
    }
}

  

    
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent" 
    android:layout_height="match_parent"
    android:paddingLeft="8dip"
    android:paddingRight="8dip">
    
    <ListView android:id="@android:id/list"
        android:layout_width="match_parent" 
        android:layout_height="0dip"
        android:layout_weight="1"
        android:stackFromBottom="true"
        android:transcriptMode="normal"/>
        
    <EditText android:id="@+id/userText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
        
</LinearLayout>

  

運用WindowManager,當滾動列表時顯示一個類似Toast的提示(android demo)


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 成人亚洲欧美日韩在线 | 在线看免电影网站 | 亚洲精品aⅴ | 狠狠色噜噜狠狠狠狠色吗综合 | 狠狠色丁香婷婷综合橹不卡 | 日本免费不卡一区二区 | 国产综合在线视频 | 天天插视频 | 欧美一区二区三区中文字幕 | 色综合天天综合网国产成人网 | 欧美日韩中文一区 | 国产大片免费观看中文字幕 | 日本成人在线看 | 亚洲综合久久伊人热 | 一级毛片 在线播放 | 国产欧美亚洲精品a | 色3344 | 三极片在线观看 | 一级片成人 | 亚洲欧洲中文日韩久久AV乱码 | 国产精品99久久久久久久女警 | 白颖宇| 日本亚洲成人 | 久色视频在线观看 | 日韩中文一区二区三区 | 天天拍天天色 | 欧美一区二区免费 | 亚洲欧美国产视频 | 日本三级一区二区三区 | 天天干天天干天天 | a在线免费观看 | 麻豆精品在线观看 | 国产一卡二卡三卡 | 日本人videos18videosrrty | 中文字幕av一区二区三区 | 在线观看亚洲专区 | 青青在线香蕉精品视频免费看 | 国产精品久久一区二区三区 | 性色网站 | 丁香六月激情婷婷 | 综合97|