首页 > 代码库 > 12月1日

12月1日

  //Activity里面编辑布局
//  LinearLayout layout= new LinearLayout(this);
//  LayoutParams param = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
//  layout.setOrientation(layout.VERTICAL);
//  TextView tv =new TextView(this);
//  tv.setText("xixi");
//  tv.setTextSize(16);
//  layout.addView(tv);
//  setContentView(layout, param);

  //获得单选的值
//  rg = (RadioGroup) findViewById(R.id.rg_sex);
//   rb = (RadioButton) findViewById(R.id.rb_man);
//   rb2 = (RadioButton) findViewById(R.id.rb_woman);
//  
//  
//  rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {
//   
//   @Override
//   public void onCheckedChanged(RadioGroup group, int checkedId) {
//    // TODO Auto-generated method stub
//    String r =null;
//    switch (checkedId) {
//    case R.id.rb_man:
//      r =rb.getText().toString().trim();
//     break;
//                     case R.id.rb_woman:
//                      r =rb2.getText().toString().trim();
//     break;
//
//
//    default:
//     break;
//    }
//    Toast.makeText(MainActivity.this, r, 200).show();
//   }
//  });

 

获取下拉框的值

 sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){

   @Override
   public void onItemSelected(AdapterView<?> arg0, View arg1,
     int arg2, long arg3) {
    String s =arg0.getItemAtPosition(arg2).toString();
    Toast.makeText(MainActivity.this, s, 200).show();
    
   }

   @Override
   public void onNothingSelected(AdapterView<?> arg0) {
    // TODO Auto-generated method stub
    
   }

长按事件

 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  setContentView(R.layout.activity_main);

  
     iv = (ImageView) findViewById(R.id.iv_long);
     iv.setOnLongClickListener(new OnLongClickListener() {
   
   @Override
   public boolean onLongClick(View v) {
    // TODO Auto-generated method stub
    
    Toast.makeText(MainActivity.this, "ni zhen bang", 100).show();
    return false;
   }
  });
   焦点
   et = (EditText) findViewById(R.id.et_fo);
  et.setOnFocusChangeListener(new OnFocusChangeListener() {
   
   @Override
   public void onFocusChange(View v, boolean hasFocus) {
    // TODO Auto-generated method stub
    Toast.makeText(getApplicationContext(), "sssssasa",200).show();
   }
  });
  
  

12月1日