單選按鈕 Radio
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對(duì)這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡(jiǎn)單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:域名注冊(cè)、網(wǎng)絡(luò)空間、營(yíng)銷軟件、網(wǎng)站建設(shè)、太平網(wǎng)站維護(hù)、網(wǎng)站推廣。
genderGroup = (RadioGroup) findViewById(R.id.genderGroup); maleButton = (RadioButton) findViewById(R.id.maleButton); femaleButton = (RadioButton) findViewById(R.id.femaleButton); //... genderGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { // TODO Auto-generated method stub if (femaleButton.getId() == checkedId) { System.out.println("female"); Toast.makeText(MainActivity.this, "female", Toast.LENGTH_SHORT).show(); } else if (maleButton.getId() == checkedId) { System.out.println("female"); Toast.makeText(MainActivity.this, "male", Toast.LENGTH_SHORT).show(); } } });
多選 CheckBox
swimBox = (CheckBox) findViewById(R.id.swim); runBox = (CheckBox) findViewById(R.id.run); readBox = (CheckBox) findViewById(R.id.read); //... swimBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if (isChecked) { System.out.println("Swim is checked"); } else { System.out.println("Swim is unchecked"); } } }); readBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if (isChecked) { System.out.println("Read is checked"); } else { System.out.println("Read is unchecked"); } } }); runBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if (isChecked) { System.out.println("Run is checked"); } else { System.out.println("Run is unchecked"); } } }); }
進(jìn)度條 ProgressBar
public class MainActivity extends ActionBarActivity { private ProgressBar firstBar = null; private ProgressBar secondBar = null; private Button myButon = null; private int i = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); firstBar = (ProgressBar) findViewById(R.id.firstBar); secondBar = (ProgressBar) findViewById(R.id.secondBar); myButon = (Button) findViewById(R.id.myButton); myButon.setOnClickListener(new ButtonListener()); } class ButtonListener implements OnClickListener{ @Override public void onClick(View v) { if (i == 0) { firstBar.setVisibility(View.VISIBLE); secondBar.setVisibility(View.VISIBLE); }else if (i < firstBar.getMax()) { //設(shè)置朱進(jìn)度條的值 firstBar.setProgress(i); //設(shè)置第二進(jìn)度條的值 secondBar.setSecondaryProgress(i + 10); //默認(rèn)的進(jìn)度條無法顯示進(jìn)行的狀態(tài) //secondBar.setProgress(i); }else { firstBar.setVisibility(View.GONE); secondBar.setVisibility(View.GONE); } i = i + 10; } } }
列表 ListView
main.xml
user.xml
MainActivity.java
public class MainActivity extends ListActivity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ArrayList> list = new ArrayList >(); HashMap map1 = new HashMap (); HashMap map2 = new HashMap (); HashMap map3 = new HashMap (); map1.put("user_name", "admin1"); map1.put("user_ip", "192.168.24.214"); map2.put("user_name", "admin2"); map2.put("user_ip", "192.168.24.215"); map3.put("user_name", "admin3"); map3.put("user_ip", "192.168.24.216"); list.add(map1); list.add(map2); list.add(map3); SimpleAdapter listAdapter = new SimpleAdapter(this, list, R.layout.user, new String[]{"user_name", "user_ip"}, new int[]{R.id.user_ip, R.id.user_name}); setListAdapter(listAdapter); } @Override protected void onListItemClick(ListView l, View v, int position, long id) { // TODO Auto-generated method stub super.onListItemClick(l, v, position, id); System.out.println("id:" + id); System.out.println("position:" + position); } }