家庭记账小账本Android studio
经过长达7天多的时间,从Android studio的安装碰到很多的问题,真的很不走运,别人安装Android studio都是一气呵成,我的Android真的没话说
把自己的这些天的开发成果展示一下
做的还是很粗略,感觉自己应该多敲一些代码啦,敲代码太慢了,还有很多不懂的,
现在我总结一下这些天遇到的问题
首先是关于Android的安装问题,起初呢,我想用esplise来做一下软件,但是同学们说软件只能由Android才能打包,esolise不能用于打包,不知道是对的还是错的,不过esplise我也安装了,需要下载ADT和sdk插件,具体方法可以网上查到,想要用esplise的同学可以试试
然后是我遇到的安装android studio的问题
首先是证书问题,我觉的应该不是网络问题,可是就是安装不好,试了很多种办法,虽然安装了证书之后可以用了,但是过了几天之后又不能用了,后来查到了很多资料,感觉可能是因为gradle没有安装好,我去网上搜集了资料,查到需要配置环境,然而,在安装Android studio的时候并没有配置,然后尝试了一下重新删除gradle‘,按照网上的方法找到了自己的版本,由重新导入,安装,配置环境变量,终于可以了
哈哈哈,然后就是自己手贱,不小心突然又给gradle升级了,结果。。。又是没有查找到有效证书,又按照原方法,重新做了一遍,赶紧把升级提醒关闭了。。无奈呀
还有一些问题我在前几天的博客里说了,现在就不重复了
最后展示一下代码,貌似在有些手机上会闪退,在接下来的几天里会加以改良
package com.example.bank; import android.database.Cursor; import android.os.Bundle; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.snackbar.Snackbar; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import android.view.View; import android.view.Menu; import android.view.MenuItem; import android.widget.ListView; import java.util.ArrayList; import java.util.List; public class MainActivity extends AppCompatActivity { private List<CostBean> mCostBeanList; private DatabaseHelper mDatabaseHelper; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); mDatabaseHelper=new DatabaseHelper(this); mCostBeanList=new ArrayList<>(); ListView costList=(ListView) findViewById(R.id.lv_main); initCostData(); costList.setAdapter(new CostListAdapter(this,mCostBeanList)); FloatingActionButton fab = findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); } private void initCostData() { mDatabaseHelper.deleteAllData(); for (int i=0;i<6;i++) { CostBean costBean=new CostBean(); costBean.costTitle=i+"mook"; costBean.costDate="11-11"; costBean.costMoney="20"; mDatabaseHelper.insertCost(costBean); } Cursor cursor= mDatabaseHelper.getAllCostData(); if(cursor !=null) { while(cursor.moveToNext()){ CostBean costBean=new CostBean(); costBean.costTitle=cursor.getString(cursor.getColumnIndex("cost_title")); costBean.costDate=cursor.getString(cursor.getColumnIndex("cost_date")); costBean.costMoney=cursor.getString(cursor.getColumnIndex("cost_money")); mCostBeanList.add(costBean); } cursor.close(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="80dp"> <TextView android:id="@+id/tv_title" android:layout_width="200dp" android:layout_height="80dp" android:layout_alignParentLeft="true" android:gravity="center" android:singleLine="true" android:text="costTitle" android:ellipsize="marquee" android:layout_marginLeft="10dp" android:textSize="35sp" /> <TextView android:id="@+id/tv_date" android:layout_width="wrap_content" android:layout_height="80dp" android:gravity="center" android:textSize="20sp" android:layout_marginLeft="15dp" android:layout_toRightOf="@id/tv_title" android:text="costDate" /> <TextView android:id="@+id/tv_cost" android:layout_width="wrap_content" android:layout_height="80dp" android:gravity="center" android:layout_alignParentRight="true" android:textSize="30sp" android:layout_marginRight="20dp" android:text="30" /> </RelativeLayout>
package com.example.bank; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import androidx.annotation.Nullable; public class DatabaseHelper extends SQLiteOpenHelper { public DatabaseHelper(@Nullable Context context) { super(context, "imooc_daily", null, 1); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL("creat table if not exists imooc_cost("+ "id integer primary key,"+ "cost_title varchar,"+ "cost_date varchar,"+ "cost_money varchar)"); } public void insertCost(CostBean costBean) { SQLiteDatabase database=getWritableDatabase(); ContentValues cv=new ContentValues(); cv.put("cost_title",costBean.costTitle); cv.put("cost_date ",costBean.costDate); cv.put("cost_money",costBean.costMoney); database.insert("imooc_cost",null,cv); } public Cursor getAllCostData(){ SQLiteDatabase database=getWritableDatabase(); return database.query("imooc_cost",null,null,null,null,null,"cost_date "+"ASC"); } public void deleteAllData(){ SQLiteDatabase database=getWritableDatabase(); database.delete("imooc_cost",null,null); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } }
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context=".MainActivity" tools:showIn="@layout/activity_main"> <ListView android:id="@+id/lv_main" android:layout_width="match_parent" android:layout_height="match_parent" /> </RelativeLayout>
做的还不算太好,有些毛病