Skip to content

Commit

Permalink
Merge pull request #452 from zhongwbang/master
Browse files Browse the repository at this point in the history
#6 #34 #第六次作业
  • Loading branch information
zengsn authored Jun 14, 2017
2 parents 5c23130 + c1bd5e0 commit 482cfa3
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabaseCorruptException;
import android.renderscript.Sampler;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.Date;
Expand Down Expand Up @@ -36,13 +37,14 @@ public void insert(Net1414080903202Account account){
values.put("yingkui",account.getYingkui());
values.put("total",account.getTotal());
//向account表插入数据values
db.insert("account",null,values);
db.close();
}

public List<Net1414080903202Account> queryAll() {
SQLiteDatabase db = helper.getReadableDatabase();
Cursor cursor = db.query("account", null, null, null, null, null, null);
List<Net1414080903202Account> list = new ArrayList<Net1414080903202Account>();
List<Net1414080903202Account> list = new ArrayList<>();
while (cursor.moveToNext()) {
String date = cursor.getString(cursor.getColumnIndex("date"));
Float input = cursor.getFloat(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ protected void onCreate(Bundle savedInstanceState) {
dao=new Net1414080903202AccountDao(this);
//从数据库中查询出所有数据
list=dao.queryAll();
Toast.makeText(this,list.size()+"",Toast.LENGTH_LONG).show();
adpater=new MyAdpapter();
accountCheck.setAdapter(adpater); //给ListView添加适配器
}
Expand Down Expand Up @@ -67,13 +68,13 @@ public View getView(int position, View convertView, ViewGroup parent) {
TextView beizhu=(TextView) item.findViewById(R.id.beizhu);
TextView yingkui=(TextView) item.findViewById(R.id.yingkui);
TextView total=(TextView) item.findViewById(R.id.total);
date.setText(list.get(position).getDate());
input.setText(list.get(position).getInput()+"");
output.setText(list.get(position).getOutput()+"");
beizhu.setText(list.get(position).getBeizhu());
yingkui.setText(list.get(position).getYingkui()+"");
total.setText(list.get(position).getTotal()+"");
return null;
date.setText("日期:"+list.get(list.size()-1-position).getDate());
input.setText("收入: "+list.get(list.size()-1-position).getInput()+"");
output.setText("支出: "+list.get(list.size()-1-position).getOutput()+"");
beizhu.setText("备注: "+list.get(list.size()-1-position).getBeizhu());
yingkui.setText("盈亏: "+list.get(list.size()-1-position).getYingkui()+"");
total.setText("余额: "+list.get(list.size()-1-position).getTotal()+"");
return item;
}

}
Expand All @@ -84,7 +85,7 @@ private class MyOnItemClickListener implements AdapterView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//获取点击位置上的数据
Net1414080903202Account a=(Net1414080903202Account) parent.getItemAtPosition(position);
Net1414080903202Account a= list.get(position);
Toast.makeText(getApplicationContext(),a.toString(),Toast.LENGTH_SHORT).show();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public Net1414080903202MyHelper(Context context){
@Override
public void onCreate(SQLiteDatabase db) {
System.out.println("onCreate");
db.execSQL("CREATE TABLE accont(date VARCHAR(20) PRIMARY KEY AUTOINCREMENT,input REA" +
db.execSQL("CREATE TABLE account(date VARCHAR(20) PRIMARY KEY,input REA" +
"L,output REAL,beizhu VARCHAR(20),yingkui REAL,total REAL)");
}
public void onUpgrade(SQLiteDatabase db,int oldVersion,int newVersion){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ public class Net1414080903202Navigation extends AppCompatActivity {

Button btManage;
Button btCheck;

Button btTest;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_net1414080903202_navigation);
btManage =(Button) findViewById(R.id.manage);
btCheck =(Button) findViewById(R.id.check) ;
btTest =(Button) findViewById(R.id.test);

btManage.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -34,5 +35,13 @@ public void onClick(View v) {
startActivity(intent);
}
});
btTest.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Net1414080903202Navigation.this, Net1414080903202ShowJson.class);
startActivity(intent);
}
});

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package edu.hzuapps.androidlabs.homeworks.net1414080903202;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import edu.hzuapps.androidlabs.R;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class Net1414080903202ShowJson extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_net1414080903202_show_json);
String a=a("https://raw.githubusercontent.com/zhongwbang/android-labs-2017/master" +
"/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks" +
"/net1414080903202/1414080903202.json");

TextView tv= (TextView) findViewById(R.id.tv_json);
tv.setText(a);

}

public String a(String u) {
try {
URL url = new URL(u);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5000);
InputStream is = conn.getInputStream();
byte[] b = new byte[1024];
StringBuilder sb = new StringBuilder();
while (is.read(b) != -1) {
sb.append(b);
}
return sb.toString();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,18 @@ public void onClick(View view){
String beizhu=et_beizhu.getText().toString().trim();
String yingkui=String.valueOf(Float.parseFloat(input)-Float.parseFloat(output));
list=accountDao.queryAll();
Float total=list.get(list.size()-1).getTotal();
Float total=0f;
if (list.size()>1)
{ total=list.get(list.size()-1).getTotal();
total=total+Float.parseFloat(yingkui);
}
else {
total=Float.parseFloat(yingkui);
}

Net1414080903202Account account=new Net1414080903202Account(date,Float.parseFloat(input),Float.parseFloat(output),beizhu,Float.parseFloat(yingkui),total);
accountDao.insert(account);
finish();
Toast.makeText(Net1414080903202manage.this,"数据提交成功",Toast.LENGTH_SHORT).show();
break;
}
Expand All @@ -68,7 +76,7 @@ public void onClick(View view){

public String getDate(){
Date date=new Date();
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return format.format(date);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<TextView
android:id="@+id/date"
android:layout_width="80dp"
android:layout_width="276dp"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginLeft="40dp"
Expand All @@ -27,7 +27,7 @@

<TextView
android:id="@+id/input"
android:layout_width="80dp"
android:layout_width="244dp"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:layout_marginLeft="40dp"
Expand All @@ -38,7 +38,7 @@

<TextView
android:id="@+id/output"
android:layout_width="80dp"
android:layout_width="246dp"
android:layout_height="wrap_content"
android:layout_marginTop="85dp"
android:layout_marginLeft="40dp"
Expand All @@ -49,7 +49,7 @@

<TextView
android:id="@+id/beizhu"
android:layout_width="80dp"
android:layout_width="244dp"
android:layout_height="wrap_content"
android:layout_marginTop="120dp"
android:layout_marginLeft="40dp"
Expand All @@ -60,7 +60,7 @@

<TextView
android:id="@+id/yingkui"
android:layout_width="80dp"
android:layout_width="242dp"
android:layout_height="wrap_content"
android:layout_marginTop="155dp"
android:layout_marginLeft="40dp"
Expand All @@ -70,7 +70,7 @@

<TextView
android:id="@+id/total"
android:layout_width="80dp"
android:layout_width="232dp"
android:layout_height="wrap_content"
android:layout_marginTop="190dp"
android:layout_marginLeft="40dp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,17 @@
tools:layout_editor_absoluteY="202dp"
tools:layout_editor_absoluteX="117dp"
tools:ignore="MissingConstraints" />

<Button
android:id="@+id/test"
android:layout_gravity="center"
android:layout_width="150dp"
android:layout_marginTop="20dp"
android:layout_height="wrap_content"
android:text="网络测试"
android:textSize="20dp"
android:onClick="click"
tools:layout_editor_absoluteY="202dp"
tools:layout_editor_absoluteX="117dp"
tools:ignore="MissingConstraints" />
</LinearLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_show_json"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="edu.hzuapps.androidlabs.homeworks.net1414080903202.Net1414080903202ShowJson">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tv_json"/>

</RelativeLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@
/>

<EditText
android:gravity="right"
android:id="@+id/input"
android:layout_width="200dp"
android:layout_height="30dp"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:layout_marginRight="80dp"
android:layout_gravity="right"
Expand Down Expand Up @@ -73,9 +74,10 @@
/>

<EditText
android:gravity="right"
android:id="@+id/output"
android:layout_width="200dp"
android:layout_height="30dp"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:layout_marginRight="80dp"
android:layout_gravity="right"
Expand Down Expand Up @@ -110,16 +112,18 @@
/>

<EditText
android:gravity="right"
android:id="@+id/beizhu"
android:layout_width="200dp"
android:layout_height="80dp"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:layout_marginRight="80dp"
android:layout_gravity="right"

/>



</FrameLayout>

<Button
Expand Down

0 comments on commit 482cfa3

Please sign in to comment.