編輯:關於Android編程
首先,是布局文件,非常的簡單,一個可以滑動的ScrollView包裹一個線性布局,線性布局裡面無內容
<scrollview 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"> <linearlayout android:id="@+id/ll" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> </linearlayout> </scrollview>
package com.neusoft.show.domal; public class Person { private String _id; private String name; private String salary; private String phone; public Person(String _id, String name, String salary, String phone) { super(); this._id = _id; this.name = name; this.salary = salary; this.phone = phone; } public String get_id() { return _id; } public void set_id(String _id) { this._id = _id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getSalary() { return salary; } public void setSalary(String salary) { this.salary = salary; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } @Override public String toString() { return _id + "," + name + ", " + salary+ ", " + phone ; } }
package com.neusoft.show; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.database.sqlite.SQLiteOpenHelper; public class MyOpenHelper extends SQLiteOpenHelper { public MyOpenHelper(Context context) { super(context,"people.db",null, 1); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL("create table person(_id integer primary key autoincrement,name char(20),salary char(20),phone char(20))"); } @Override public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) { // TODO Auto-generated method stub System.out.print("數據庫升級了!!!"); } }
package com.neusoft.show; import java.util.ArrayList; import java.util.List; import com.neusoft.show.domal.Person; import android.R.integer; import android.os.Bundle; import android.app.Activity; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.view.Menu; import android.widget.LinearLayout; import android.widget.TextView; public class MainActivity extends Activity { ListpersonList; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); personList=new ArrayList (); //從數據庫裡面把數據取出來 MyOpenHelper oh = new MyOpenHelper(this); SQLiteDatabase db = oh.getWritableDatabase(); Cursor cursor = db.query("person", null, null, null, null, null, null); while (cursor.moveToNext()) { String _id = cursor.getString(cursor.getColumnIndex("_id")); String name = cursor.getString(cursor.getColumnIndex("name")); String salary = cursor.getString(cursor.getColumnIndex("salary")); String phone = cursor.getString(cursor.getColumnIndex("phone")); Person p=new Person(_id, name, salary, phone); personList.add(p); } LinearLayout ll=(LinearLayout) findViewById(R.id.ll); //把數據顯示到屏幕 for(Person p:personList) { //1.集合中每有一條數據,就new一個TextView TextView tv=new TextView(this); //2.把人物的信息設置為文本的內容 tv.setText(p.toString()); tv.setTextSize(18); //3.把TextView設置成線性布局的子節點 ll.addView(tv); } } }
1.背景目前網絡中圖片仍然是占用流量較大的一部分,對於移動端更是如此,因此,如何在保證圖片視覺不失真前提下縮小體積,對於節省帶寬和電池電量十分重要。然而目前對於JPEG、
Notification通知參考地址:http://developer.android.com/training/notify-user/index.html通知(Not
我們在使用ListView的時候,很多情況下需要用到下拉刷新的功能。為了了解下拉刷新的底層實現原理,我采用自定義ListView控件的方式來實現效果。實現的基本原理是:自
關於Android4.4的圖片路徑獲取,如果回來的Uri的格式有兩種 content://com.android.providers.med