android 程式碼片段

來源:互聯網
上載者:User

1、listView去除點擊時背景的黑色:android:cacheColorHint="#00000000"

2、RatingBar監聽數目改變:level.setOnRatingBarChangeListener (new RatingBar.OnRatingBarChangeListener () {

            public void onRatingChanged (RatingBar ratingBar, float rating, boolean fromUser) {
            float r=level.getRating();
            }
        });

3、取消EditText的自動彈出鍵盤:在AndroidMenifest檔案中的該Activity中添加    android:windowSoftInputMode="stateAlwaysHidden"

4、AlterDialog中添加checkBox:

                         final CharSequence[] items = {"1","2","3"}; 
    AlertDialog.Builder builder = new AlertDialog.Builder(Xianchang.this);
      builder.setTitle("選擇要顯示的圖層");
      builder.setMultiChoiceItems(items,new boolean[]{false,false,false},new DialogInterface.OnMultiChoiceClickListener() {
                public void onClick(DialogInterface dialog,int whichButton, boolean isChecked) {
                    /* User clicked on a check box do some stuff */
                                }
            });
    AlertDialog alert = builder.create();
    alert.show();

5、listView中的CheckBox擷取選中的資訊:

                         holder.cBox.setOnCheckedChangeListener(new OnCheckedChangeListener(){
           @Override
           public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
           if(isChecked)
           {
           receivers.add((Person)data.get(arg0).get("person"));
           }
           else{
           receivers.remove((Person)data.get(arg0).get("person"));
           }
           }});

6、在AlertDialog中顯示圖片:

                                        ImageView i=new ImageView(Report1.this);
        i.setImageBitmap(bm);
        AlertDialog imageDialog = new AlertDialog.Builder(Report1.this).create();
        imageDialog.setView(i);
        imageDialog.show();

7、調用系統網路攝影機:

                                 Intent i = new Intent("android.media.action.IMAGE_CAPTURE");  
startActivityForResult(i, Activity.DEFAULT_KEYS_DIALER); 

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == Activity.DEFAULT_KEYS_DIALER) {
            if (resultCode == RESULT_OK) {
               
            }
        }
    }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.