Android简单笔记本解析(期中作业)

Android简单笔记本解析(期中作业)

1.成品展示

1.1初始界面展示

在这里插入图片描述

1.2添加功能展示
在这里插入图片描述
1.3查询功能展示
在这里插入图片描述

2.搜索功能(根据标题查询)

搜索图标(list_options_menu.xml)

<item
    android:id="@+id/menu_search"
    android:title="@string/menu_search"
    android:icon="@android:drawable/ic_search_category_default"
    android:showAsAction="always">
</item>

搜索的声明(AndroidManifest.xml)

<activity
    android:name="NoteSearch"
    android:label="@string/title_notes_search">
</activity>

添加搜索(NoteList–onOptionsItemSelected方法)

case R.id.menu_search:
       Intent intent = new Intent();
       intent.setClass(NotesList.this,NoteSearch.class);
       NotesList.this.startActivity(intent);
       return true;

布局搜索页面(note_search_list.xml)
SearchView和ListView分别用来实现搜索功能和显示搜索出来的条目

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <SearchView
        android:id="@+id/search_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:iconifiedByDefault="false"
        android:queryHint="输入搜索内容..."
        android:layout_alignParentTop="true">
    </SearchView>

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"></ListView>

</LinearLayout>

查询按钮的监听器、查询列表的监听器以及查询界面的初始化(NoteSearch)



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 = 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)

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    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放入垂直线性布局内就好了

<!--添加一个垂直的线性布局-->
<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <!--原标题TextView-->
    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        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/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"
        />
</LinearLayout>

在数据库中存放时间(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
            R.layout.noteslist_item, // Points to the XML for a list item
            cursor,   // The cursor to get items from
            dataColumns,
            viewIDs
    );
// Sets the ListView's adapter to be the cursor adapter that was just created.
setListAdapter(adapter);

写到这里差不多就完成了时间戳和查询功能的实现。
作者姓名:游嘉豪
原文链接

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
android开发期末大作业(项目源码,任务书,实验大报告,apk文件) 大作业的要求和内容:(包括题目选择范围、技术要求、递交时间、考核方法等) 一、实验项目名称 Android手机应用开发课程大作业 二、实验目的 1.通过本课程设计的实践及其前后的准备与总结,复习、领会、巩固和运用课堂上所学的Android手机应用开发知识。 2.为学生综合应用本专业所学习的多门课程知识(例如,软件工程、数据库、Java语言、Java Web开发等)创造实践机会。为学生提供主动学习、积极探索与大胆创新的机会。 3.掌握Android手机应用设计的方法与技巧。 三、实验内容及要求 1、设计内容 题目、设计内容自拟,工作量适中,要求学生应用课程所学知识,采用JAVA语言和Android手机应用开发技术实现一个完整的系统。 ①完成大作业报告。 ②实现各系统功能,并完成调试运行。 2、主要技术 采用Java语言并不仅限于Java语言实现系统。 开发环境与工具:Android Studio 3.2以上版本; 操作系统:Win7/Win10或其他; 4、设计成果: 材料上交:电子文档(大作业任务书+大作业报告+源代码,电子稿请刻在光盘上)、打印稿(大作业任务书+大作业报告)。 四、成绩评定: 考核标准包括: 1、选题的工作量,难度和新颖程度 2、系统架构设计是否良好,运行过程是否报错 3、界面设计的合理性和美观程度 4、基本功能的实现 分值60 (包括布局、组件、Activity、Intent等使用) 数据存储的使用 分值10 网络功能 分值10 Service、ContentProvider或BroadCastReceiver等的使用 分值10 附加分: 图形图像处理、多媒体处理等 分值10 5、考核方式为面对面答辩,在课程的后两周内集中进行。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值