㈠ android單選按鈕
你要當成單選的一組的radiobutton要放在radioGROUP下,不然這個GROUP就沒起作用
只有這樣寫,才能實現這組radiobutton是單選的效果。
㈡ android listview單選如何獲取當前選中是否勾選
1、使用checked屬性判斷選中,代碼為if($(this).attr("checked")){alert("選中了");}。
2、jquery獲取radio單選按鈕的值。以上就是androidlistview單選獲取勾選當前選中指的方法。
㈢ android布局listview中怎麼樣設置下拉與單選按鈕
android裡面沒有表格,只有列表,要做到這樣的效果很麻煩的。
android裡面的ui是適合手機的,這種列表,特別是右邊的那個下拉按鈕,不適合手機這種屏幕小的設備。比如說下拉,android裡面用的是spinner,通常是屏幕居中彈出,當然也可以設置下拉,設置下拉屏幕的利用不高啊,要顯示完數據都不容易。
也就是說這種針對PC的界面設計,建議你最好做一些調整來符合android的特性。當然,如果真的要實現,也是可以實現的。
左邊的就是checkBox,最右邊可以用Spinner,也可以自定義或用其它View來實現 ,比如說Button,左drawable,右drawable,點擊後彈出popWindow.
至於這種樣式,最好是把listView放在RelativeLayout中,把線條畫在listView上,模擬出表格樣式。
㈣ android單選按鈕
你要當成單選的一組的radiobutton要放在radioGROUP下,不然這個GROUP就沒起作用
只有這樣寫,才能實現這組radiobutton是單選的效果。
㈤ 如何實現android中三個單選按鈕橫向排列且只能選一個
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/row_item_margin">
<TextView
android:id="@+id/tvStorageWay"
style="@style/EditTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="儲存方式:"/>
<RadioGroup
android:id="@+id/rgStorageWay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/tvStorageWay"
android:gravity="center_vertical"
android:orientation="horizontal">
<RadioButton
android:id="@+id/rbPack"
style="@style/EditTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@null"
android:drawableLeft="@drawable/selector_login_mode_radiobutton"
android:text="包裝"/>
<RadioButton
android:id="@+id/rbBulk"
style="@style/EditTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/row_item_margin"
android:layout_weight="1"
android:button="@null"
android:drawableLeft="@drawable/selector_login_mode_radiobutton"
android:text="散裝"/>
<RadioButton
android:id="@+id/rbStorageWayOther"
style="@style/EditTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/row_item_margin"
android:layout_weight="1"
android:button="@null"
android:drawableLeft="@drawable/selector_login_mode_radiobutton"
android:text="其它"/>
</RadioGroup>
</RelativeLayout>
㈥ Android-RadioButton單選按鈕控制項詳解
RadioButton是單選按鈕,允許用戶在一個組中選擇一個選項。同一組中的單選按鈕有互斥效果。
1.RadioButton是圓形單選框;
2.RadioGroup是個可以容納多個RadioButton的容器;
3.在RadioGroup中的RadioButton控制項可以有多個,但同時有且僅有一個可以被選中。
基本的使用就是上面Demo說的那樣。在Android開發當中,我們也可以使用RadioButton控制項來實現應用的底部導航欄。
㈦ Android studio 單選按鈕怎麼更改點擊後的樣式
button設置null之後再設置background,自己創建個selector就行了
㈧ android 用imageview實現單選功能
imageView2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
v.setBackgroundResource(null); v.setBackgroundResource(R.drawable.adddoorbellon);
ImageView imageView = (ImageView) findViewById(R.id.yimenling_oneclick);
imageView.setBackgroundResource(R.drawable.akeyconfiguration);
}
});
這樣試試,,最好把你的錯誤日誌發出來
㈨ 關於Android界面組件的基本用法
1.文本框(TextView)和編輯框(EditText)
文本框(TextView)不允許用戶編輯文本內容,而編輯框(EditText)允許用戶編輯文本內容
2.按鈕(Button)和圖片按鈕(ImageButton)
Button顯示文字,ImageButton顯示圖片。
為ImageButton指定android:text屬性沒用,不會顯示文字
可以指定android:background為按鈕增加背景圖片,但這圖片是固定的
可以指定android:src為圖片按鈕增加圖片屬性
其實,src才是設置圖標,而background只是設置背景。
如果控制項的大小是100 100 圖片資源是80 80的話,那麼用src,圖片就會居中顯示,如果使用background那麼圖片就會被拉伸充滿控制項。
重要的是,background是底層的圖片資源,src是覆蓋在background上面的資源,他們可以疊加使用,實現選中的效果。
3.單選按鈕(RadioButton)和復選框(CheckBox)
多了一個android:checked屬性,用於指定初始時是否被選中
4.計時器組件Chronometer用法
紅色字體表示常用的方法
5.圖像視圖(ImageView)
它支持屬性android:scaleType setScaleType(ImageView.ScaleType)
matrix(ImageView.ScaleType.MATRIX):使用matrix方式進行
fixXY(ImageView.ScaleType.FIX_XY):對圖片橫向縱向獨立縮放,會改變縱橫比
fitStart(ImageView.ScaleType.FIT_START):保持縱橫比,圖片較長的邊長與ImageView相應的邊長相等,縮放後放在左上角
fitCenter(ImageView.ScaleType.FIT_CENTER):保持縱橫比,圖片較長的邊長與ImageView相應的邊長相等,縮放後放在中央
fitEnd(ImageView.ScaleType.FIT_END):保持縱橫比,圖片較長的邊長與ImageView相應的邊長相等,縮放後放在右下角
center(ImageView.ScaleType.CENTER):放中間,不縮放
centerCrop(ImageView.ScaleType.CENTER_CROP):保持縱橫比,使圖片能完全覆蓋ImageView
centerInside(ImageView.ScaleType.CENTER_INSIDE):保持縱橫比,使ImageView能完全顯示圖片
6.spinner的功能和用法
如果可以確定spinner裡面的列表項,那麼直接在/res/layout/main.xml裡面指定
然後在/res/value/string.xml裡面指定
如果不確定裡面的列表項,那麼必須要提供一個Adapter,這個Adapter負責決定Spinner列表每項的內容
7.日期、時間選擇器(DatePicker和TimePicker)
8.自動完成文本框(AutoCompleteTextView)
比普通文本框多了一個功能:當用戶輸入一定字元後,自動完成文本框會顯示一個下拉菜單,供用戶從中選擇,當用戶選擇某個菜單後,組件會按用戶選擇自動填寫該文本框
使用該組件很簡單,只要為它設置一個Adapter,該Adapter封裝了AutoCompleteTextView預設的提示文本
9.進度條(ProgressBar)
通過style屬性可以為ProgressBar指定風格。該屬性可以有如下的屬性值:
1.@android:style/Widget.ProgressBar.Horizontal 水平進度條
2.@android:style/Widget.ProgressBar.Inverse 不斷跳躍、旋轉畫面的進度條
3.@android:style/Widget.ProgressBar.Large 大進度條
4.@android:style/Widget.ProgressBar.Large.Inverse不斷跳躍、旋轉畫面的大進度條
5.@android:style/Widget.ProgressBar.Small 小進度條
6.@android:style/Widget.ProgressBar.Small.Inverse不斷跳躍、旋轉畫面的小進度條
ProgressBar提供如下方法來操作進度
1.setProgress(int) 設置進度的完成百分比
2.incrementProgressBy(int) 設置進度條的增加或減少。參數為正增加,參數為負減少
10.選項卡(TabHost)
TabHost僅僅只是一個簡單的容器,它提供如下方法
1.newTabSpec(String tag) 創建選項卡
2.addTab(TabHost.TabSpec tabSpec) 添加選項卡
使用TabHost的一般步驟為:
• A. 在界面中定義TabHost組件,並為該組件定義該選項卡的內容
• B. Activity應該繼承TabActivity
• C. 調用TabActivity的getTabHost()來獲取TabHost對象
• D. 通過TabHost對象的方法來創建選項卡、添加選項卡
選項卡主要由TabHost、TabWidget、FrameLayout3個組件組成,三者缺一不可,想像一下選項卡的特點,多個卡重疊在一起,所以用FrameLayout即幀布局是必要的。另外需要注意的是TabHost、TabWidget、FrameLayout三個組件的android:id必須使用系統默認的名稱,而不能自己隨意定義,否則會出錯。
11.圖像切換器(ImageSwitcher)
12.網格視圖(GridView)
使用GridView一般指定numColumn大於1,否則取默認值為1.那麼GridView就變成了ListView
屬性android:stretchMode支持如下屬性
1.none 不拉伸
2.spacingWidth 僅拉伸元素之間的間距
3.spacingWidthUniform 表格、元素之間的間距一起拉伸
4.columnWidth 僅拉伸表格
13.畫廊視圖(Gallery)(現在已經被棄用了,不過還是列出來吧)
Gallery用法很簡單——為它提供一個內容Adapter,該Adapter的getView方法所返回的View可作為Gallery的列表項。可以通過OnItemSelectedListener監聽選擇項的改變
14.列表試圖(ListView和ListActivity)
1.創建ListView由兩種方式:
2.直接使用ListView進行創建
讓Activity繼承ListActivity(繼承了ListActivity的類無需調用setContentView()來顯示頁面,可以直接設置適配器)
一旦獲得ListView後,就要創建顯示的列表項了。需要藉助內容Adapter,內容Adapter負責提供需要顯示的列表項
創建ArrayAdapter時必須指定一個textViewResourceId,該參數決定每個列表項的外觀
1.simple_list_item_1 每個列表項是普通的TextView
2.simple_list_item_2 每個列表項是普通的TextView(字體略大)
3.simple_list_item_checked 每個列表項是已勾選的列表項
4.simple_list_item_multiple_choice 每個列表項是帶多選框的文本
5.simple_list_item_single_choice 每個列表項是帶多單選按鈕的文本
15.使用AlertDialog
1.創建AlertDialog.Builder對象,該對象是AlertDialog的創建器
2.調用AlertDialog.Builder方法為對話框設置圖標、標題等
3.調用AlertDialog.Builder的create()方法創建AlertDialog對話框
4.調用AlertDialog的show()方法顯示對話框
16.使用Toast顯示提示框
步驟如下:
• 調用Toast構造器或makeText方法創建Toast對象
• 調用Toast方法來設置該消息的對齊方式等
• 調用Toast的show()方法顯示出來
• Toast toast = Toast.makeText(ToastTest.this, "信息", Toast.LENGTH_LONG).show();
17.Notification(一般顯示網路狀態、電池狀態、時間等)
使用Notification發送Notification步驟:
• 調用getSystemService(NOTIFICATION_SERVICE)方法獲取系統的Notification Manager服務
• 通過構造器創建一個Notification對象
• 為Notification設置屬性
• 通過Notification Manager發送Notification
㈩ 求 android RadioButton屬性詳解
一: 單選按鈕RadioButton在Android平台上也應用的非常多,比如一些選擇項的時候,會用到單選按鈕,實現單選按鈕由兩部分組成,也就是RadioButton和RadioGroup配合使用
RadioButton的單選按鈕;
RadioGroup是單選組合框,用於將RadioButton框起來;
在沒有RadioGroup的情況下,RadioButton可以全部都選中;
當多個RadioButton被RadioGroup包含的情況下,RadioButton只可以選擇一個;
注意:單選按鈕的事件監聽用setOnCheckedChangeListener來對單選按鈕進行監聽
例子:一道選擇題,選擇哪個城市美女最多,當然,這個就是為了測試
Java代碼
1.package org.loulijun.radio;
2.
3.import android.app.Activity;
4.import android.os.Bundle;
5.import android.view.Gravity;
6.import android.widget.RadioButton;
7.import android.widget.RadioGroup;
8.import android.widget.TextView;
9.import android.widget.Toast;
10.
11.public class RadioTest extends Activity {
12. /** Called when the activity is first created. */
13. TextView textview;
14. RadioGroup radiogroup;
15. RadioButton radio1,radio2,radio3,radio4;
16. @Override
17. public void onCreate(Bundle savedInstanceState) {
18. super.onCreate(savedInstanceState);
19. setContentView(R.layout.main);
20. textview=(TextView)findViewById(R.id.textview1);
21. radiogroup=(RadioGroup)findViewById(R.id.radiogroup1);
22. radio1=(RadioButton)findViewById(R.id.radiobutton1);
23. radio2=(RadioButton)findViewById(R.id.radiobutton2);
24. radio3=(RadioButton)findViewById(R.id.radiobutton3);
25. radio4=(RadioButton)findViewById(R.id.radiobutton4);
26.
27. radiogroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
28.
29. @Override
30. public void onCheckedChanged(RadioGroup group, int checkedId) {
31. // TODO Auto-generated method stub
32. if(checkedId==radio2.getId())
33. {
34. DisplayToast("正確答案:"+radio2.getText()+",恭喜你,回答正確!");
35. }else
36. {
37. DisplayToast("請注意,回答錯誤!");
38. }
39. }
40. });
41. }
42. public void DisplayToast(String str)
43. {
44. Toast toast=Toast.makeText(this, str, Toast.LENGTH_LONG);
45. toast.setGravity(Gravity.TOP,0,220);
46. toast.show();
47. }
48.}
strings.xml文件
Xml代碼
1.<?xml version="1.0" encoding="utf-8"?>
2.<resources>
3. <string name="hello">哪個城市美女多?</string>
4. <string name="app_name">單選按鈕測試</string>
5. <string name="radiobutton1">杭州</string>
6. <string name="radiobutton2">成都</string>
7. <string name="radiobutton3">重慶</string>
8. <string name="radiobutton4">蘇州</string>
9.</resources>
main.xml文件:注意,這裡面,4個RadioButton包含在RadioGroup中
Xml代碼
1.<?xml version="1.0" encoding="utf-8"?>
2.<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3. android:orientation="vertical"
4. android:layout_width="fill_parent"
5. android:layout_height="fill_parent"
6. >
7.<TextView
8. android:layout_width="fill_parent"
9. android:layout_height="wrap_content"
10. android:text="@string/hello"
11. android:id="@+id/textview1"
12. />
13. <RadioGroup
14. android:id="@+id/radiogroup1"
15. android:layout_width="wrap_content"
16. android:layout_height="wrap_content"
17. android:orientation="vertical"
18. android:layout_x="3px"
19. >
20. <RadioButton
21. android:id="@+id/radiobutton1"
22. android:layout_width="wrap_content"
23. android:layout_height="wrap_content"
24. android:text="@string/radiobutton1"
25. />
26. <RadioButton
27. android:id="@+id/radiobutton2"
28. android:layout_width="wrap_content"
29. android:layout_height="wrap_content"
30. android:text="@string/radiobutton2"
31. />
32. <RadioButton
33. android:id="@+id/radiobutton3"
34. android:layout_width="wrap_content"
35. android:layout_height="wrap_content"
36. android:text="@string/radiobutton3"
37. />
38. <RadioButton
39. android:id="@+id/radiobutton4"
40. android:layout_width="wrap_content"
41. android:layout_height="wrap_content"
42. android:text="@string/radiobutton4"
43. />
44. </RadioGroup>
45.</LinearLayout>
二:Android 自定義RadioButton的樣式(和上面關系不大)
我們知道Android控制項里的button,listview可以用xml的樣式自定義成自己希望的漂亮樣式。
最近用到RadioButton,利用xml修改android:background="@drawable/button_drawable",其中button_drawable為自己定義的.xml文件(res/drawable文件下),但是不成功,到網上查找,也沒有正確的說法,我就開始自己嘗試,最後做好了。
其實方法很簡單,同樣在res/drawable新建radiobutton.xml如下
Xml代碼
1.<selector xmlns:android="http://schemas.android.com/apk/res/android">
2.
3. <item
4.
5.
6. android:state_enabled="true"
7.
8. android:state_checked="true"
9.
10. android:drawable="@drawable/check" />
11.
12. <item
13.
14. android:state_enabled="true"
15.
16. android:state_checked="false"
17.
18. android:drawable="@drawable/checknull" />
19.
20. </selector>
check和checknull分別為選中和位選中的圖片。
然後在你的布局文件中,RadioButton 布局
設置android:button = "@drawable/radiobutton",就可以了!