当前位置: 编程技术>移动开发
本页文章导读:
▪歌曲歌词同步展示 歌曲歌词同步显示
在播放歌曲时添加屏幕一直高亮显示
......
▪ ExpandableListView控件的运用 ExpandableListView控件的使用
ExpandableListView控件的简单使用这里的布局没有进行美化,只是功能的简单实现。先看一下效果图:[img][/img]点击展开后效果:[img][/img]工程结构图:[img][/img]三个布.........
▪ Intent小运用:打电话 Intent小应用:打电话
Intent小应用:打电话MainActivity:package com.amaker.call;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android..........
[1]歌曲歌词同步展示
来源: 互联网 发布时间: 2014-02-18
歌曲歌词同步显示
在播放歌曲时添加屏幕一直高亮显示
在播放歌曲时添加屏幕一直高亮显示
[2] ExpandableListView控件的运用
来源: 互联网 发布时间: 2014-02-18
ExpandableListView控件的使用
ExpandableListView控件的简单使用
这里的布局没有进行美化,只是功能的简单实现。
先看一下效果图:
[img]
[/img]
点击展开后效果:
[img]
[/img]
工程结构图:
[img]
[/img]
三个布局文件:
首先,第一个布局文件main.xml是在主界面定义一个ExpandableListView ,在这里我们就要和在做ListView是的方法做下对比了,其实这个listView的显示类似。主要是用来显示ExpandableListView 下的数据。第二个布局文件是定义ExpandableListView 下的一级条目目录。在这里我只为一级条目目录添加一个textView控件。第三个布局文件是定义ExpandableListView 下的二级条目目录,和一级条目目录一样,布局文件里也只有一个TextView控件。
main.xml
groups.xml
childs.xml
ExpandableActivity:
这个控件和ListView很相似,在学习的过程中,可以结合ListView的用法的来使用。
ExpandableListView控件的简单使用
这里的布局没有进行美化,只是功能的简单实现。
先看一下效果图:
[img]
[/img]
点击展开后效果:
[img]
[/img]
工程结构图:
[img]
[/img]
三个布局文件:
首先,第一个布局文件main.xml是在主界面定义一个ExpandableListView ,在这里我们就要和在做ListView是的方法做下对比了,其实这个listView的显示类似。主要是用来显示ExpandableListView 下的数据。第二个布局文件是定义ExpandableListView 下的一级条目目录。在这里我只为一级条目目录添加一个textView控件。第三个布局文件是定义ExpandableListView 下的二级条目目录,和一级条目目录一样,布局文件里也只有一个TextView控件。
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ExpandableListView
android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@id/android:empty"
android:text="No Data"/>
</LinearLayout>
groups.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/group"
android:textSize="25sp"
android:paddingLeft="35px"
android:paddingTop="10px"
android:paddingRight="5px"
android:paddingBottom="10px"
android:text="No Data"/>
</LinearLayout>
childs.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/child"
android:textSize="15sp"
android:paddingLeft="25px"
android:paddingTop="10px"
android:paddingRight="5px"
android:paddingBottom="10px"
android:text="No Data"/>
</LinearLayout>
ExpandableActivity:
package com.amaker.expandable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.ExpandableListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.SimpleExpandableListAdapter;
/**
* 继承ExpandableListActivity类
*/
public class ExpandableActivity extends ExpandableListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 创建一级条目
List<Map<String, String>> groups = new ArrayList<Map<String, String>>();
//创建两个一级条目标题
Map<String, String> group1 = new HashMap<String, String>();
group1.put("group", "音乐");
Map<String, String> group2 = new HashMap<String, String>();
group2.put("group", "歌词");
groups.add(group1);
groups.add(group2);
// 创建一级条目下的的二级条目
List<Map<String, String>> child1 = new ArrayList<Map<String, String>>();
//同样是在一级条目目录下创建两个对应的二级条目目录
Map<String, String> childdata1 = new HashMap<String, String>();
childdata1.put("child", "青花瓷");
Map<String, String> childdata2 = new HashMap<String, String>();
childdata2.put("child", "东风破");
child1.add(childdata1);
child1.add(childdata2);
//同上
List<Map<String, String>> child2 = new ArrayList<Map<String, String>>();
Map<String, String> childdata3 = new HashMap<String, String>();
childdata3.put("child", "青花瓷.lrc");
Map<String, String> childdata4 = new HashMap<String, String>();
childdata4.put("child", "东风破.lrc");
child2.add(childdata3);
child2.add(childdata4);
// 将二级条目放在一个集合里,供显示时使用
List<List<Map<String, String>>> childs = new ArrayList<List<Map<String, String>>>();
childs.add(child1);
childs.add(child2);
/**
* 使用SimpleExpandableListAdapter显示ExpandableListView
* 参数1.上下文对象Context
* 参数2.一级条目目录集合
* 参数3.一级条目对应的布局文件
* 参数4.fromto,就是map中的key,指定要显示的对象
* 参数5.与参数4对应,指定要显示在groups中的id
* 参数6.二级条目目录集合
* 参数7.二级条目对应的布局文件
* 参数8.fromto,就是map中的key,指定要显示的对象
* 参数9.与参数8对应,指定要显示在childs中的id
*/
SimpleExpandableListAdapter adapter = new SimpleExpandableListAdapter(
this, groups, R.layout.groups, new String[] { "group" },
new int[] { R.id.group }, childs, R.layout.childs,
new String[] { "child" }, new int[] { R.id.child });
setListAdapter(adapter);
}
/**
* 设置哪个二级目录被默认选中
*/
@Override
public boolean setSelectedChild(int groupPosition, int childPosition,
boolean shouldExpandGroup) {
//do something
return super.setSelectedChild(groupPosition, childPosition,
shouldExpandGroup);
}
/**
* 设置哪个一级目录被默认选中
*/
@Override
public void setSelectedGroup(int groupPosition) {
//do something
super.setSelectedGroup(groupPosition);
}
/**
* 当二级条目被点击时响应
*/
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
//do something
return super.onChildClick(parent, v, groupPosition, childPosition, id);
}
}这个控件和ListView很相似,在学习的过程中,可以结合ListView的用法的来使用。
[3] Intent小运用:打电话
来源: 互联网 发布时间: 2014-02-18
Intent小应用:打电话
Intent小应用:打电话
MainActivity:
main.xml
配置文件:
Intent小应用:打电话
MainActivity:
package com.amaker.call;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
/**
* 1,打电话ciao测试
*,2,从联系人中获取电话号码,拨打
* ZZL
*/
public class MainActivity extends Activity {
private Button btn_select;
private Button btn_call;
private EditText et_number;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn_select = (Button) findViewById(R.id.button1);
btn_call = (Button) findViewById(R.id.button2);
et_number = (EditText) findViewById(R.id.editText1);
btn_select.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
select();
}
});
btn_call.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
call();
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Uri uri = data.getData();
String[] strs = {"number"};
Cursor c = managedQuery(uri, strs, null, null, null);
c.moveToFirst();
String number = c.getString(c.getColumnIndexOrThrow("number"));
et_number.setText(number);
}
//查找联系人
void select(){
Intent intent = new Intent();
String action = Intent.ACTION_GET_CONTENT;
String type = "vnd.android.cursor.item/phone";
intent.setAction(action);
intent.setType(type);
startActivityForResult(intent, 0);
}
//打电话
void call(){
String action = Intent.ACTION_CALL;
String number = et_number.getText().toString();
Uri data = Uri.parse("tel:"+number);
Intent intent = new Intent();
intent.setAction(action);
intent.setData(data);
startActivity(intent);
}
}main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="请输入电话号码:" /> <EditText android:id="@+id/editText1" android:phoneNumber="true" android:layout_width="match_parent" android:layout_height="wrap_content" /> <Button android:text="查询电话号码" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Button android:text="CALL" android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>
配置文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.amaker.call"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
最新技术文章: