一开始,我在点点上发布文章的,但浏览量至少,真实让人难过。现打算来这里,留下一些痕迹。这是我点点的博客。Comfish
![](https://img-my.csdn.net/uploads/201211/29/1354187275_8721.jpg)
(2)activity_lvm.xml
(3)activity_lvu.xml
转载不必注明 Comfish
以前是写时评,当学习了语言之后,对时事政治失去了兴趣。一时找不到写文章的感觉。这里,相信可以让我畅所欲言。
昨天才开始学习android,原本是看书的,但学生不才,还是去找视频来学习了。遇到很多小麻烦,都用了我不少的时间和精力去解决。比如ADK突然启动不了之类。所以,我挺怕遇到麻烦,以为麻烦一来,学习进度就拖慢了,跟大姨妈的功效有点像。
因为是初学,分享不了太多的技术,同时我也可以把技术方面的东西简化。因为我写博客的目的,是记载,记载我如何学习android,记载期间的感受。想学技术的朋友,这里暂时无法提供什么技术,但我相信,以后,总有那天,你会在这里找到你想要的内容。
今天在群上认识了一位朋友,它也是刚学android。我问他为什么学android,他说是想做一款软件,要拿去卖,卖了以后应该就不再写了。这样看来,他是一位老前辈了。对于他们来说,学习一门新的语言,就像出去工作几天。入门的时候可能比较辛苦。但后面是绝对的行云流水。
我想这是每个程序员有了一定的积累,才能到达的境界。
下面开始复习一下这次的内容:
【1】布局:LinearLayout 、LinearLayout
1)LinearLayout 线性布局
2)
RelativeLayout 相对布局
相对布局是普遍使用的布局。
个人觉得,一定要去学习一下HTML+CSS。当我们学习完网页布局之后,对与这些布局,应该是很容易上手的。
RelativeLayout
![](https://img-my.csdn.net/uploads/201211/29/1354187253_6298.png)
【2】组件:RadioButton、RadioGroup、CheckBox。
1)RadioButton放在RadioGroup里实现单选效果。
2)CheckBox是复选框。
3)他们添加事件的方法有所不同,如下。
rg.setOnCheckedChangeListener( new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
if(rb1 .getId()==checkedId){
Toast. makeText(Button_Activity.this,
"Hello world",Toast.LENGTH_SHORT).show();
}
}
});
cb1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
Toast. makeText(Button_Activity.this,
"oh my god~~~~!!!!",Toast.LENGTH_SHORT).show();
}
}
});
【3】
Toast
![](https://img-my.csdn.net/uploads/201211/29/1354187257_5287.jpg)
1)上面有一个Toast,我还不知道这属于什么。可是它能实现如提示框的效果。有一种解释是,土司,当你烤土司的时候,“叮~~”会飞出两片,所以,Toast也是飞出来的。
2)
Toast. makeText(Button_Activity.
this
,
"Hello world"
,Toast.
LENGTH_SHORT
).show();
1>"Hello world"是显示文本,
2>Toast. LENGTH_SHORT 是显示的时间长短
3>千万别忘了后面的.show();
【4】ProgressBar: 进度条
![](https://img-my.csdn.net/uploads/201211/29/1354187262_7450.png)
<
ProgressBar
android:id
=
"@+id/pb1"
style
=
"?android:attr/progressBarStyleHorizontal"
android:layout_width
=
"fill_parent"
android:layout_height
=
"wrap_content"
android:visibility
=
"gone"
/>
1>第三行是设置进度条的样式。如果还有其它样式,请同学自行寻找。
2>最后一行是将进度条的视图视为消失(进度条一般是需要的时候才会显示出来)
使用方法如下:
————————————————————————————————————————————
![](https://img-my.csdn.net/uploads/201211/29/1354187270_9178.png)
【5】 ListView
1)效果如下:
有两个布局文件,一个是布局当前Activity,一个是布局ListView。
因为不懂得如何描述。所以只能在文章后面贴出代码。
![](https://img-my.csdn.net/uploads/201211/29/1354187275_8721.jpg)
代码如下:
(1)ListView_Activity.java
package com.example.sdd;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
public class ListView_Activity extends ListActivity {
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
if(id==1){
Toast.makeText(ListView_Activity.this,
"What the fuck?",Toast.LENGTH_SHORT).show();
}
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lvm);
ArrayList<HashMap<String ,String>> list = new ArrayList<HashMap<String,String>>();
HashMap<String,String> map1 = new HashMap<String ,String>();
HashMap<String,String> map2 = new HashMap<String ,String>();
HashMap<String,String> map3 = new HashMap<String ,String>();
map1.put("name", "Comfish");
map1.put("id", "123456");
map2.put("name", "steve");
map2.put("id", "343434");
map3.put("name", "jobs");
map3.put("id", "565767");
list.add(map1);
list.add(map2);
list.add(map3);
SimpleAdapter listAdapter = new SimpleAdapter(this,list,
R.layout.activity_lvu,new String[]{"name","id"},//S他ring[]那里,获取需要显示的键名。放在下面相应的TextView里显示
new int[]{R.id.tv1_name,R.id.tv1_id});//最后一个int是通过R获取相应的TextView的id,也就是显示的位置.
setListAdapter(listAdapter);
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:id="@+id/tv1_lv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="show the list : "/>
<LinearLayout
android:id="@+id/listLinearLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#444"
android:orientation="vertical"
>
<ListView
android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
></ListView>
</LinearLayout>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<TextView
android:id="@+id/tv1_name"
android:layout_width="160dip"
android:layout_height="30dip"
android:singleLine="true"
android:textColor="#eee"
/>
<TextView
android:id="@+id/tv1_id"
android:gravity="right"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#eee" />
</LinearLayout>
转载不必注明 Comfish