栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Android简单笔记本解析,成功入职头条月薪35K

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Android简单笔记本解析,成功入职头条月薪35K

public class NoteSearch extends ListActivity implements

SearchView.onQueryTextListener {

private static final String[] PROJECTION = new String[] {

NotePad.Notes._ID, // 0

NotePad.Notes.COLUMN_NAME_TITLE, // 1

//扩展 显示时间 颜色

NotePad.Notes.COLUMN_NAME_MODIFICATION_DATE // 2

//NotePad.Notes.COLUMN_NAME_BACK_COLOR

};

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.note_search_list);

Intent intent = getIntent();

if (intent.getData()

== null) {

intent.setData(NotePad.Notes.CONTENT_URI);

}

SearchView searchview =

(SearchView)findViewById(R.id.search_view);

//为查询文本框注册监听器

searchview.setonQueryTextListener(NoteSearch.this);

}

@Override

public boolean onQueryTextSubmit(String query) {

return false;

}

@Override

public boolean onQueryTextChange(String newText) {

String selection = NotePad.Notes.COLUMN_NAME_TITLE + " Like ? ";

String[] selectionArgs = { “%”+newText+"%" };

Cursor cursor = managedQuery(

getIntent().getData(), PROJECTION,

selection, selectionArgs, NotePad.Notes.DEFAULT_SORT_ORDER

);

String[] dataColumns = {

NotePad.Notes.COLUMN_NAME_TITLE

, NotePad.Notes.COLUMN_NAME_MODIFICATION_DATE };

int[]

viewIDs = { android.R.id.text1

, R.id.text1_time };

SimpleCursorAdapter adapter = new SimpleCursorAdapter(

this,

R.layout.noteslist_item,

cursor,

dataColumns,

viewIDs

);

setListAdapter(adapter);

return true;

}

@Override

protected void onListItemClick(ListView l, View v, int position, long

id) {

Uri uri = ContentUris.withAppendedId(getIntent().getData(),

id);

String action

《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》

【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享

= getIntent().getAction();

if (Intent.ACTION_PICK.equals(action)

|| Intent.ACTION_GET_CONTENT.equals(action)) {

setResult(RESULT_OK, new Intent().setData(uri));

} else {

startActivity(new Intent(Intent.ACTION_EDIT, uri));

}

}

}

3.时间戳的实现


在文本下方显示时间

文本标题(noteslist_item.xml)

android:id="@android:id/text1"

android:layout_width=“match_parent”

android:layout_height="?android:attr/listPreferredItemHeight"

android:textAppearance="?android:attr/textAppearanceLarge"

android:gravity=“center_vertical”

android:paddingLeft=“5dip”

android:singleLine=“true”

/>

我们要在标题下方添加时间,那么可以再写一个时间的TextView,把标题和时间的TextView放入垂直线性布局内就好了

android:id="@+id/layout"

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:orientation=“vertical”>

android:id="@android:id/text1"

android:layout_width=“match_parent”

android:layout_height="?android:attr/listPreferredItemHeight"

android:textAppearance="?android:attr/textAppearanceLarge"

android:gravity=“center_vertical”

android:paddingLeft=“5dip”

android:singleLine=“true”

/>

android:id="@+id/text1_time"

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:textAppearance="?android:attr/textAppearanceSmall"

android:text="@string/text_title"

android:paddingLeft=“5dip”

/>

在数据库中存放时间(NotePadProvider)

public void onCreate(SQLiteDatabase db) {

db.execSQL(“CREATE TABLE " + NotePad.Notes.TABLE_NAME + " (”

  • NotePad.Notes._ID + " INTEGER PRIMARY KEY,"

  • NotePad.Notes.COLUMN_NAME_TITLE + " TEXT,"

  • NotePad.Notes.COLUMN_NAME_NOTE + " TEXT,"

  • NotePad.Notes.COLUMN_NAME_CREATE_DATE + " INTEGER,"

  • NotePad.Notes.COLUMN_NAME_MODIFICATION_DATE + " INTEGER"

  • “);”);

}

通过Cursor从数据库中读取出

Cursor cursor = managedQuery(

getIntent().getData(), // Use the default content URI for the provider.

PROJECTION, // Return the note ID and title for each note.

null, // No where clause, return all records.

null, // No where clause, therefore no where column values.

NotePad.Notes.DEFAULT_SORT_ORDER // Use the default sort order.

);

通过SimpleCursorAdapter装填

String[] dataColumns = { NotePad.Notes.COLUMN_NAME_TITLE } ;

int[] viewIDs = { android.R.id.text1 };

SimpleCursorAdapter adapter

= new SimpleCursorAdapter(

this, // The Context for the ListView

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/644083.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号