zoukankan      html  css  js  c++  java
  • 记账本开发6

    今天完成账单的显示。(代码参考自CSDN、百度等)

    package com.example.myapp0;
    import androidx.appcompat.app.AppCompatActivity;
    import android.widget.ImageButton;
    import android.widget.ListView;
    import android.widget.Toast;
    import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.view.View; import java.util.ArrayList; import java.util.List; public class ZD extends AppCompatActivity
    { private List<Account> accountList=new ArrayList<Account>(); private ListView listView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_zd); initAccount(); AccountAdapter adapter=new AccountAdapter(ZD.this,R.layout.item,accountList); listView=findViewById(R.id.zd); listView.setAdapter(adapter); } private void initAccount()
      {
    MyDatabaseHelper databaseHelper=new MyDatabaseHelper(this); SQLiteDatabase db=databaseHelper.getWritableDatabase(); Cursor cursor=db.query("AcountBook",null,null,null,null,null); while(cursor.moveToNext())
         { String je
    =cursor.getString(cursor.getColumnIndex("je")); String name=cursor.getString(cursor.getColumnIndex("name")); String bz=cursor.getString(cursor.getColumnIndex("bz")); String time=cursor.getString(cursor.getColumnIndex("time")); Account account=new Account(je,name,bz,time); accountList.add(account); } } }
    package com.example.myapp0;

    import android.widget.ArrayAdapter;
    import android.widget.TextView;
    import android.content.Context;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import java.util.List;
    public class AccountAdapter extends ArrayAdapter
    {
    private final int resourceId; public AccountAdapter(Context context,int textViewResourceId,List<Account> objects){ super(context,textViewResourceId,objects); resourceId=textViewResourceId; } @Override public View getView(int position, View convertView, ViewGroup parent)
      { Account account
    = (Account) getItem(position); View view = LayoutInflater.from(getContext()).inflate(resourceId, null); TextView je,name,bz,time; je=view.findViewById(R.id.je); name=view.findViewById(R.id.name); bz=view.findViewById(R.id.bz); time=view.findViewById(R.id.time); je.setText(account.getJe()); name.setText(account.getName()); bz.setText(account.getBz()); time.setText(account.getTime()); return view; } }
    
    
  • 相关阅读:
    USDT与omniCore钱包
    C# 事件(第四章)
    委托进阶(第三章)
    委托入门(第二章)
    委托入门(第一章)
    asp.net页面生命周期
    在WEB程序中小心使用"ThreadStatic"
    如何在一个请求中共享数据或对象实例
    .net垃圾回收机制原理
    MVC模式简介
  • 原文地址:https://www.cnblogs.com/hfy717/p/14443437.html
Copyright © 2011-2022 走看看