1. Activity.setContentView(int layoutResID)
Set the activity content from a layout resource. The resource will be inflated, adding all top-level views to the activity.
2. Activity.findViewById(int id)
Finds a view that was identified by the id attribute from the XML that was processed in onCreate.
Activity在onCreate方法中,通过setContentView实例化layout描述的控件。之后,通过findViewById获取控件实例。所以,findViewById只是通过resId找到setContentView实例化的控件并返回View的引用,而非创建View后再返回其引用。因此,同一个activity实例,多次调用findViewById获取到的某个resId的View实例是同一个的。
分享到:
相关推荐
Activity中常用的函数有SetContentView() findViewById() finish() startActivity(),其生命周期涉及的函数有: void onCreate(Bundle savedInstanceState) void onStart() void onRestart() void onResume() void ...
在Android程序中,有时候需要加载非原来activity中xml布局中的控件,来使Android程序的界面更加丰富。 我本身是在使用ViewFlipper中遇到的问题。 public void onCreate(Bundle savedInstanceState) { super....
activity.setContentView(R.layout.activity_duk) button1 = activity.findViewById(R.id.button1); button1.setOnClickListener(new OnClickListener(function(){ Toast.makeText(activity, "Button1 Clicked",...
在这儿通常可以 调用 setContentView(int)设置在资源文件中定义的 UI, 使用 findViewById(int) 可以获得 UI 中定义的窗口. onPause()接口是使用者准备离开 activity 的地方,在这儿,任何的 修改都应该被提交(通常...
1.只需要解决怎么找到那个Framelayout,我这里想到的办法是给每个xml布局的根元素设置一个id,通过findViewById找到咋们通过setContentView设置上布局, 再通过View的view.getParent();得到它的父元素。它的父...
setContentView(R.layout.main); //获取button对象 Button btn1 = (Button)findViewById(R.id.button1); Button btn2 = (Button)findViewById(R.id.button2); Button btn3 = (Button)findViewById(R.id.button3); ...
setContentView(R.layout.main); btnLogin=(Button) findViewById(R.id.btnLogin); btnGoToWeb=(Button) findViewById(R.id.btnGoToWeb); show=(TextView) findViewById(R.id.A1show); btnLogin.setOnClickListener...
一个模仿酷狗播放器滑动返回的layout可以让你的app有更丰富 便捷的手势操作支持activity滑动返回和普通layout的滑动 显示/隐藏 两种模式,可以参考demo里面的...kugouLayout.setContentView(R.layout.activity_main);
setContentView(R.layout.activity_main); get1 = (Button) findViewById(R.id.button1); iv = (ImageView) findViewById(R.id.imageView1); rl = (RelativeLayout) findViewById(R.id.back); get1....
setContentView R layout biptphone ; call Button findViewById R id btnCall ; back Button findViewById R id btnBack ; phoneNum EditText findViewById R id phoneNum ; Listener4Back new ...
setContentView(R.layout.main_activity); findViewById(); buttonListion(); mBluetoothAdapter=BluetoothAdapter.getDefaultAdapter(); if(mBluetoothAdapter==null) { Toast.makeText(context, ...
setContentView(MResource.getIdByName(getApplication(), "layout", "activity_main")); TextView mTextView = (TextView) findViewById(MResource.getIdByName(getApplication(), "id", "textView1")); ...
setContentView(R.layout.activity_main); button1 = (Button) findViewById(R.id.button1); tv = (TextView) findViewById(R.id.tv); button1.setOnClickListener(this); UUID uuid = UUID.randomUUID();...
setContentView(R.layout.login); TextView registerScreen = (TextView) findViewById(R.id.link_to_register); // Listening to register new account link registerScreen.setOnClickListener(new View....
setContentView(R.layout.main); Buttonbtn=(Button)findViewById(R.id.button); Buttonbtn2=(Button)findViewById(R.id.button2); btn.setOnClickListener(listener); btn2.setOnClickListener(listener2);} ...
setContentView(R.layout.main); mobileText = (EditText)this.findViewById(R.id.mobile); Button button = (Button)this.findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener()...
setContentView(R.layout.activity_main); rb1=(RadioButton)findViewById(R.id.rb1); rb2=(RadioButton)findViewById(R.id.rb2); rb3=(RadioButton)findViewById(R.id.rb3); rg=(RadioGroup)...
setContentView(R.layout.activity_main); ArrayAdapter<String> arrayAdapter=new ArrayAdapter( MainActivity.this,android.R.layout.simple_list_item_1,msWordS ); ListView listView = findViewById(R....
setContentView(R.layout.button); text_show=(TextView)findViewById(R.id.text_show); edit_0=(EditText)findViewById(R.id.edit_0); Button button_send=(Button)findViewById(R.id.button_send); button_...
button=(Button)findViewById(R.id.second_Button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(SecondActivity....