您的位置:首页 > 编程语言 > Java开发

android(eclipse)界面控件以及活动总结(二)

2016-03-19 23:42 337 查看
用户界面以及活动总结:

(复习时忘了的特别标记了下划线,补充的用了红色)

1用户界面:

~android:id=""专门用于找到指定界面的索引 如果要在后面的程序中调用该控件,则一定要定义此属性
~引用控件的方式:xml中@id/** 代码中R.id.**
<TextView
android:layout_width="wrap_content"
abdroid:layout_height="wrap_content"
android:text=".."
/>
<EditText
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:inputType="该处可以决定输入的内容数据类型"/>
<Button
android:id="@+id/send"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="button"
android:onClick(可以在xml中设定点击按钮的方法?)/>

public void send(View v) {

Intent intent = new Intent(this, MainActivity.class);

startActivity(intent);

}//在代码中直接实现,到此,就一共有三种方法实现button的监听事件了,匿名类,实现接口加上这个。

//选择控件 可以调用isChecked()是否被选取了
<CheckBox
android:layout_height="wrap_content"
android:lalout_width="wrap_content"
android:checked="true/false"/>
//用于创建一个具有选择功能的集合
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<RadioButton
android:text="-"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<RadioButton
android:text="+"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</RadioGroup>

菜单的使用:创建Menu laylout文件定义

<item android:id="@+id/item1"
android:icon="@drawable/rightarrow"
          android:title="item1"/>
<item .......
/>
public boolean onCreateOptionsMenu(Menu menu){
MenuInflater inflater=getMenuInflater();
return super.onCreateOptionMenu(menu);
}
响应菜单事件
public boolean onOptionItemSelected(MenuItem item){
swith(item.getItemId()){//此处要注意他与v.getId()的不同
case R.id.item1:
..
break;
case R.id.item2:
..
break;}
return super.onOptionItemSelected(item);}

2活动:
~启动活动的三种方式:在manifest文件声明第一个要进入的活动
使用ContentWrapper对象的startActicity()来启动活动
使用startActivityForResults
~<action android:name="android.intent.action.MAIN"/> //表明该活动为程序进入点
<category android:name="android.intent.category.LAUNCHER"/>//将程序的图标显示在安装列表当中
~setContentView(int)
finfViewById(R.****)
setOnClickListener(new OnclickListener(){
@Override
public void onClick(View V){}
});
~活动的管理是使用堆栈管理的//返回时就先返回的是栈顶元素
~android系统并不会主动删除已经使用过的任何一个活动除非是内存不够才会按优先级关闭
~创建事件处理方法有两种android:onClick 和使用匿名内部类 **.setOnClickListener( new OnclickListener(){public void onClick(View void){}});
~长按事件处理.setOnLongClickListener(new onClickListener(){piblic void onLongClick(){}});
~Toast.makeText(this,"",Toast.LENGTH_SHORT).show();弹出一段暂时显示的文字事件
~使用意图启动活动步骤:1建立活动点击按钮触发第二个活动 2定义第二个活动以及独立的布局3在Manifest中注册主活动的action和category以及次活动的名称
~活动之间传递数据:发送:
Intent intent=new Intent(this,activity.class);
Bundle bundle=new Bundle();
bundle.putString("键值",a.getText().toString);
intent.putExtra(bundle);将bundle附加给下一个
startActicity(intent);
接收:Bundle bundle=this.getIntent().getExtras();
if(bundle!=null){c=Integer.pareInt(bundle.getString("键值")}//把字符串的数据转化为整型 pare:削皮 修剪
~启动内置应用程序
Intent intent=new Intent(intent.ACTION_VIEW,Uri.parse("http://www.google.com.hk"));startActicity(intent) ;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: