建立多重選單必須使用AlertDialog.Builder 來達成, 如下
package com.example.layout; import android.app.Activity; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnMultiChoiceClickListener; import android.os.Bundle; import android.util.Log; public class MultiChoiceItemsActivity extends Activity { protected static final String TAG = "MultiChoiceItemsActivity"; private String[] mItems = new String[] { "item1", "item2", "item3", "item4", "item5" }; private boolean[] mCheckItems = new boolean[mItems.length]; private void showAlertDialog() { Builder builder = new AlertDialog.Builder(this); builder.setTitle("Title"); builder.setMultiChoiceItems(mItems, mCheckItems, new OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { if (isChecked) { mCheckItems[which] = true; } } }); builder.setNegativeButton("Negative", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String checkItemsResult = ""; int checkItemslength = mCheckItems.length; for (int i = 0; i < checkItemslength; ++i) { if (mCheckItems[i]) { checkItemsResult = checkItemsResult + mItems[i]; } } Log.d(TAG, checkItemsResult); } }); builder.show(); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_multi_choice_items); showAlertDialog(); } }
第17行為多重選項的內容
第21行為紀錄哪些選項被選擇
第27行設定多重選項並傳入顯示的選項內容
第32行藉由isChecked判斷哪些選項被勾選,並紀錄在mCheckItems中
第38行加入Button
第43~50行為顯示被勾選的選項
Denese
15 3 月, 2015 10:01 上午Hi blogger, i found this post on 18 spot in google’s search results.
You should reduce your bounce rate in order to rank in google.
This is major ranking factor nowadays. There is very
useful wordpress plugin which can help you.
Just search in google for:
Seyiny’s Bounce Plugin
https://www.youtube.com/
27 3 月, 2015 12:16 上午Hello! I understand this is kind of off-topic but I had to ask.
Does building a well-established website
such as yours require a massive amount work? I’m completely new to
running a blog however I do write in my diary everyday.
I’d like to start a blog so I can share my experience and feelings online.
Please let me know if you have any kind of suggestions
or tips for brand new aspiring bloggers. Appreciate it!
foxx
30 3 月, 2015 11:36 上午Sorry for late reply~~
If you want a simple blog just use google blogger. It is free but ugly.
My website built on ubuntu os and some service must be installed like tomcat , mysql , wordpress, public ip address.
It took me 2~3 days to finish all job.
If your want to know more detail about my website, email to me ^^