編輯:關於Android編程
MainActivity如下:
package cc.testradiogroup;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.app.Activity;
/**
* Demo描述:
* 利用自定義RadioGroup實現單選
*
* 參考資料:
* 1 http://blog.csdn.net/xiaanming
* 2 http://bbs.51cto.com/thread-954128-1.html
*
* Thank you very much
*/
public class MainActivity extends Activity {
private RadioGroup mRadioGroup;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
}
private void init(){
mRadioGroup=(RadioGroup) findViewById(R.id.radioGroup);
mRadioGroup.setOnCheckedChangeListener(new RadioButtonOnCheckedChangeListenerImpl());
}
// 監聽單選的變化
private class RadioButtonOnCheckedChangeListenerImpl implements OnCheckedChangeListener {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
RadioButton rb = (RadioButton) findViewById(group.getCheckedRadioButtonId());
String currentSelected = rb.getText().toString();
System.out.println(現在選中是: + currentSelected);
}
}
}
main.xml如下:
text_selector.xml如下:
??
ViewPropertyAnimator源碼分析
最近對android中的動畫特別感興趣,可能是因為比較喜歡跟UI相關的東西吧。這篇文章將簡單的介紹下ViewPropertyAnimator這個類的源碼和一些使用。簡述V
Android M 動態權限獲取
新的權限獲取方式除了要求像之前版本一樣在AndroidManifest文件中靜態申請之外,應用還需根據需要請求權限,方式采用向用戶顯示一個請求權限的對話框。這些被動態申
Android 中自定義控件之判斷還剩多少可輸入字符的EditText
最近做的項目有個需求就是判斷一下還 剩多少字符可輸入,也就是對EditText 的文本變化做監聽 ,功能實現了,但是感覺使用組合方式,每次都要編寫,還不如寫
學習Android自定義Spinner適配器
本文為大家分享Android自定義Spinner適配器的相關知識點,供大家參考,具體內容如下一、大致效果二.關鍵代碼在注釋中講重點吧。 (1)Spinner的布局: ca