当前浏览

海思笔记→第10页

分类目录

展开|收起

看你喜欢

(1) (1) (42) (1) (1) (1) (16) (2) (1) (1) (4) (1) (2) (7) (4) (1) (1) (1) (1) (3) (1) (5) (1) (1) (1) (1) (1) (2) (1) (4) (4) (3) (1) (1) (2) (1) (37) (2) (1) (5) (3) (1) (4) (1) (1) (11) (3) (1) (9) (3) (1) (23) (2) (1) (2) (1) (1) (1) (1)

最新精华

第 10 页,共 20 页« 最新...89101112...20...最旧 »

《Android应用开发详解》- Chapter04_UI_List02 – 列表视图(Simple Cursor Adapter)

本例演示通过游标Adapter(Simple Cursor Adapter)来添加列表视图内容。

1. 布局文件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"
    >

</LinearLayout>

2. MainActivity.java

package com.amaker.test;

import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.widget.ListAdapter;
import android.widget.SimpleCursorAdapter;

public class MainActivity extends ListActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Cursor c = getContentResolver().query(People.CONTENT_URI, null, null, null, null);
        startManagingCursor(c);
       
        ListAdapter adapter = new SimpleCursorAdapter(this, 
                android.R.layout.simple_list_item_1, 
                c, 
                new String[] {People.NAME} ,
                new int[] {android.R.id.text1}); 
        setListAdapter(adapter);
    }
}

3. 运行结果

Chapter04_UI_List02

Chapter04_UI_List02-1

Chapter04_UI_List02实例源码:

Chapter04_UI_List02
标题: Chapter04_UI_List02 (878 次点击)
文件: Chapter04_UI_List02.7z
大小: 16 kB
描述:

  打分:5.0/5 (共1人投票)

《Android应用开发详解》- Chapter04_UI_List01 – 列表视图(ArrayAdapter)

列表视图可以说是Android中最为常用的一种视图组件,它以垂直列表的方式列出需要显示的列表项。创建ListView既可以使用ListView组件,也可以继承ListActivity。在使用中重要的是如何设置选项内容,也就是如何设置Adapter,Adapter既可以是一个简单的数值Adapter(Array Adapter),也可以是一个游标Adapter(Simple Cursor Adapter),还可以继承BaseAdapter展示其它视图。本例演示使用Array Adapter来添加列表视图内容。

1. 布局文件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"
    >

</LinearLayout>

2. MainActivity.java

package com.amaker.test;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;

public class MainActivity extends ListActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String[] strs = {"Java","C","C++","VB"};
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,strs);
        setListAdapter(adapter);
    }
}

3. 运行结果

Chapter04_UI_List01

Chapter04_UI_List01实例源码:

Chapter04_UI_List01
标题: Chapter04_UI_List01 (788 次点击)
文件: Chapter04_UI_List01.7z
大小: 14 kB
描述:

  打分:5.0/5 (共1人投票)

《Android应用开发详解》- Chapter04_UI_DatePicker_TimePicker – 日期、时间选择对话框

1. 布局文件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:text="" android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<TextView android:text="" android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<Button android:text="更改日期" android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text="更改时间" android:id="@+id/Button02" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>


</LinearLayout>

2. MainActivity.java

package com.amaker.test;

import java.util.Calendar;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.app.TimePickerDialog.OnTimeSetListener;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.TimePicker;

public class MainActivity extends Activity {
	private Button b1,b2;
	private TextView tv1,tv2;
	private Calendar c;
	private int m_year,m_month,m_day;
	private int m_hour,m_minute;
	
   
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        b1 = (Button)findViewById(R.id.Button01);
        b2 = (Button)findViewById(R.id.Button02);
        
        c = Calendar.getInstance();
        
        m_year = c.get(Calendar.YEAR);
        m_month = c.get(Calendar.MONTH);
        m_day = c.get(Calendar.DAY_OF_MONTH);
        
        m_hour = c.get(Calendar.HOUR);
        m_minute = c.get(Calendar.MINUTE);
        
        tv1 = (TextView)findViewById(R.id.TextView01);
        
        tv1.setText(m_year+":"+(m_month+1)+":"+m_day);
        
        tv2 = (TextView)findViewById(R.id.TextView02);
        tv2.setText(m_hour+":"+m_minute);
        
        b1.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				showDialog(0);
			}
		});
        
        b2.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				showDialog(1);
			}
		});
    }
    protected Dialog onCreateDialog(int id) {
    	if(id==0)
    	return new DatePickerDialog(this,
                l1,
                m_year, m_month, m_day);
    	else
    		return new TimePickerDialog(this,
                    l2, m_hour, m_minute, false);
    }
    
    private OnDateSetListener l1 = new OnDateSetListener() {
		public void onDateSet(DatePicker view, int year, int monthOfYear,
				int dayOfMonth) {
			m_year = year;
			m_month = monthOfYear;
			m_day = dayOfMonth;
			tv1.setText(m_year+":"+(m_month+1)+":"+m_day);
		}
	};
	
	private OnTimeSetListener l2 = new OnTimeSetListener() {
		public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
			m_hour = hourOfDay;
			m_minute = minute;
			tv2.setText(m_hour+":"+m_minute);
		}
	};
}

3. 运行结果

Chapter04_UI_DatePicker_TimePicker-1

Chapter04_UI_DatePicker_TimePicker-2

Chapter04_UI_DatePicker_TimePicker-3

Chapter04_UI_DatePicker_TimePicker实例源码:

Chapter04_UI_DatePicker_TimePicker
标题: Chapter04_UI_DatePicker_TimePicker (813 次点击)
文件: Chapter04_UI_DatePicker_TimePicker.7z
大小: 19 kB
描述:

  打分:5.0/5 (共2人投票)

视频: 华为Ascend P6发布会

华为P6伦敦发布会全程完整视频,总长66分钟,基本相当于官方版:

华为P6移动版发布会,中国移动总裁李跃盛赞华为p6:

  打分:5.0/5 (共3人投票)

《Android应用开发详解》- Chapter04_UI_ProgressBar03 – 水平进度条

1. 布局文件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"
    >
<ProgressBar 
	android:id="@+id/ProgressBar01" 
	style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="200dip"
    android:layout_height="wrap_content"
    android:max="100"
    android:progress="50"
></ProgressBar>

<Button 
android:id="@+id/Button01" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="增加"></Button>

<Button 
android:id="@+id/Button02" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="減少"></Button>

</LinearLayout>

2. MainActivity.java

package com.amaker.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;

public class MainActivity extends Activity {
	private Button b1,b2;
	ProgressBar progressBar;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        b1 = (Button)findViewById(R.id.Button01);
        b2 = (Button)findViewById(R.id.Button02);
        progressBar = (ProgressBar)findViewById(R.id.ProgressBar01);
        
        b1.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
					progressBar.incrementProgressBy(1);
			}
		});
        
        b2.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				progressBar.incrementProgressBy(-1);
			}
		});
        
    }
}

3. 运行结果

Chapter04_UI_ProgressBar03-1

Chapter04_UI_ProgressBar03-2

Chapter04_UI_ProgressBar03实例源码:

Chapter04_UI_ProgressBar03
标题: Chapter04_UI_ProgressBar03 (810 次点击)
文件: Chapter04_UI_ProgressBar03.7z
大小: 71 kB
描述:

  打分:5.0/5 (共1人投票)

《Android应用开发详解》- Chapter04_UI_ProgressBar02 – 标题栏进度条

1. 布局文件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"
    >

<Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="显示"></Button>
<Button android:id="@+id/Button02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="隐藏"></Button>
</LinearLayout>

2. MainActivity.java

package com.amaker.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
	
	private Button b1,b2;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
       requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
       setContentView(R.layout.main);
       b1 = (Button)findViewById(R.id.Button01);
       b2 = (Button)findViewById(R.id.Button02);
       
       b1.setOnClickListener(new OnClickListener() {
		public void onClick(View v) {
			setProgressBarIndeterminateVisibility(true);
		}
       });
       
       b2.setOnClickListener(new OnClickListener() {
   		public void onClick(View v) {
   			setProgressBarIndeterminateVisibility(false);
   		}
       });
    }
}

3. 运行结果

Chapter04_UI_ProgressBar02-1

Chapter04_UI_ProgressBar02-2

Chapter04_UI_ProgressBar02实例源码:

Chapter04_UI_ProgressBar02
标题: Chapter04_UI_ProgressBar02 (784 次点击)
文件: Chapter04_UI_ProgressBar02.7z
大小: 70 kB
描述:

  打分:5.0/5 (共1人投票)
第 10 页,共 20 页« 最新...89101112...20...最旧 »