首页 > 其他分享 >安卓开发七——主管理页面

安卓开发七——主管理页面

时间:2024-02-03 19:36:54浏览次数:21  
标签:安卓 视图 开发 import android null void 页面

新增月份管理页面,将新增账本移植到这个页面

主页面视图

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center">

    <TextView
        android:gravity="center"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="40sp"
        android:text="@string/month"
        />
    <View
        android:layout_width="fill_parent"
        android:layout_marginTop="10dp"
        android:layout_height="1dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:background="#aa000000" />
    <ListView
        android:id="@+id/l_month"
        android:layout_width="match_parent"
        android:layout_height="560dp" />
    <ImageButton
        android:id="@+id/add"
        android:onClick="addAccount"
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:scaleType="centerInside"
        android:layout_centerHorizontal="true"
        android:background="#00FF0000"
        android:src="@drawable/img"
        android:layout_below="@+id/list_view" />
</LinearLayout>

列表视图的元件

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="80dp"
    android:id="@+id/month"
    android:layout_marginLeft="20dp"
    android:layout_alignParentLeft="true"
    android:gravity="center"
    android:singleLine="true"
    android:textSize="30sp"
    android:ellipsize="marquee"
    android:text="costTitle">

</TextView>

页面视图适配代码

package com.example.myapplication;

import android.annotation.SuppressLint;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.os.Message;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.AdapterView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import java.util.ArrayList;
import java.util.List;
import android.os.Handler;

public class monthActivity extends AppCompatActivity {
    List<String> list;
    private ImageButton Add;
    private DBHelper helper;
    private ListView listView;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.month);
        Add=findViewById(R.id.add);
        listView=findViewById(R.id.l_month);
        iniView();
    }
    @SuppressLint("Range")
    private void iniView()
    {
        helper=new DBHelper(monthActivity.this);
        list=new ArrayList<>();
        SQLiteDatabase db=helper.getReadableDatabase();
        Cursor cursor=db.query("account2",null,null,null,null,
                null,null);
        while (cursor.moveToNext()){
            String mon=cursor.getString(cursor.getColumnIndex("Date")).substring(0,7);
            if(!find(mon))
            {
                list.add(mon);
            }
        }
        db.close();
    }
    public void addAccount(View view){//跳转
        Intent intent=new Intent(monthActivity.this,new_cost.class);
        //noinspection deprecation
        startActivityForResult(intent,1);
    }
    public boolean find(String a)
    {
        boolean flag=false;
        for (String str : list) {
            if(str.equals(a))
            {
                flag=true;
                break;
            }
        }
        return flag;
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==1&&resultCode==1)
        {
            iniView();
        }
    }
}

这样我们基本所有的页面视图都完成了

主页面:

 账本页面

添加页面

 

标签:安卓,视图,开发,import,android,null,void,页面
From: https://www.cnblogs.com/zhenaifen/p/17999028

相关文章

  • 安卓开发六——账本的条目视图的适配
    我们的一条数据项目包括,收入(指出)、说明、日期、金额四项,所以我们要自定义一个适配器这里适配器的一个列表的各个单位的类型是一个打包好的类的类型。这个类也是自己创建的packagecom.example.myapplication;publicclasscostList{privateString_id;privateS......
  • 安卓开发五——创建数据库和增加数据
    packagecom.example.myapplication;importandroid.content.Context;importandroid.database.sqlite.SQLiteDatabase;importandroid.database.sqlite.SQLiteOpenHelper;publicclassDBHelperextendsSQLiteOpenHelper{privatestaticintDB_VERSION=1;......
  • 安卓开发四——账本基本页面
    账本基本页面就是一个添加页面,一个浏览页面,浏览页面的一条数据项是一个视图。<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto&quo......
  • 安卓开发十——调试设置应用图标和源代码
    我们要设置图标和名称只需要修改这三个值就就可以了android:icon="@drawable/appimag"android:label="记账本"android:roundIcon="@drawable/appimag"然后最后的效果是这样的    源代码:<?xmlversion="1.0"encoding="utf-8&......
  • 安卓开发九——长按删除记录和定时刷新页面
    这里我们完成了账本条目数据的查看方法和账本条目的添加,但是当我们发现账本的数据有错误是,我们目前还不能删除。于是我们接下来要完成条目的删除的功能。这里我们在查看某个的账本的明细的页面来操作,我这里采用设置长按下删除。listView.setOnItemLongClickListener(new......
  • 安卓开发二——项目内容和页面跳转
     创建一个初始目录后会又以下的几个文件目录manifests中有一个Androidmanifests.xml的文件它包含了我们这个软件的图标、名字等的基本信息 其中的activity标签中是我们的app所要使用的页面的注册信息 Java的文件目录中我们主要使用的就是第一个文件目录,其中的Java代码包......
  • 安卓开发1——安装Android studio
    去网上找Android的studio1的下载教程找到对应的下载链接,下载 因为我有安装完成后就把下载的软件安装的文件删除的习惯所以就不展示了具体的安装教程可以看AndroidStudio安装配置教程-Windows(详细版)-CSDN博客 安装后新建项目完成后在最右侧的第三个可以挑选自己安卓......
  • uni-app小程序开发 基础 #2月摸鱼计划01
    前言:最近看uni-app框架的时候发现了这套课程,看到网络上大都是收费的资料,所以打算把这份资源开源共享出来,如果觉得有帮助的话,务必支持一下,关注......
  • 解锁教育系统源码的定制奥秘:企业培训平台开发详解
    今天,小编将为大家讲解教育系统源码的奥秘,详细解释企业培训定制开发的关键步骤和技术要点。 一、需求分析与设计阶段设计阶段则包括系统的整体架构设计、数据库设计以及用户界面设计等方面。二、技术选型与开发环境搭建通过使用版本控制系统、集成开发环境(IDE)以及一系列的测试工具,......
  • 剧本杀小程序开发:从创意到实现
    近年来,剧本杀作为一种新兴的社交娱乐形式,迅速在年轻人中走红。它不仅是一种推理游戏,更是一种社交体验。随着智能手机的普及和移动互联网的快速发展,剧本杀小程序应运而生,为玩家提供了更加便捷的参与方式和全新的游戏体验。本文将探讨剧本杀小程序的开发过程,包括创意的产生、市场分析......