当前位置:操作系统 > 安卓/Android >>

Toast温馨小提示

例子一:
Java代码 
Button btn2 = (Button)findViewById(R.id.button2); 
    btn2.setOnClickListener(new OnClickListener() { 
    @Override 
        public void onClick(View v) { 
LayoutInflater vi = (LayoutInflater) 
getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
            View view = vi.inflate(R.layout.main, null); 
            TextView tv = (TextView)view.findViewById(R.id.textView); 
tv.setText("文本小提示"); 
Toast toast = new Toast(ToastView.this); 
toast.setView(view); 
toast.setDuration(Toast.LENGTH_SHORT); 
toast.show(); 

}); 

例子二:
Java代码 
super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    RadioGroup r = (RadioGroup)findViewById(R.id.radioGroup1); 
    r.setOnCheckedChangeListener(new OnCheckedChangeListener() { 
             
        @Override 
        public void onCheckedChanged(RadioGroup group, int cheId) { 
            //cheId为点击的radio的id 
            Toast.makeText(ActivityTest.this, "test", Toast.LENGTH_SHORT).show(); 
        } 
}); 

PS:ActivityTest.this是类本身,比如例二是指在ActivityTest引用的方法

作者“rayln”
 

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,