Revisão | 95 (tree) |
---|---|
Hora | 2013-11-15 16:12:07 |
Autor | t-nakamura |
得点、アシストをDBに登録するようにしました。
@@ -3,11 +3,15 @@ | ||
3 | 3 | import jp.co.versus.R; |
4 | 4 | import jp.co.versus.adapter.PlayResultEditorListAdapter; |
5 | 5 | import jp.co.versus.adapter.PlayResultEditorListAdapter.PlayResultEditorListItem; |
6 | +import jp.co.versus.provider.VersusContract.Point; | |
7 | +import jp.co.versus.provider.VersusContract.Team; | |
6 | 8 | import android.app.Activity; |
9 | +import android.content.ContentResolver; | |
10 | +import android.content.ContentValues; | |
7 | 11 | import android.content.Intent; |
12 | +import android.database.Cursor; | |
8 | 13 | import android.graphics.Color; |
9 | 14 | import android.os.Bundle; |
10 | -import android.util.Log; | |
11 | 15 | import android.view.ContextMenu; |
12 | 16 | import android.view.MenuItem; |
13 | 17 | import android.view.View; |
@@ -45,6 +49,8 @@ | ||
45 | 49 | private TextView score2; |
46 | 50 | private ListView listView; |
47 | 51 | private PlayResultEditorListAdapter adapter; |
52 | + private int mResultId = 0; | |
53 | + private ContentResolver mContentResolver; | |
48 | 54 | |
49 | 55 | @Override |
50 | 56 | public void onCreate(Bundle savedInstanceState){ |
@@ -66,6 +72,7 @@ | ||
66 | 72 | score1 = (TextView)findViewById(R.id.scoreinit_label1); |
67 | 73 | score2 = (TextView)findViewById(R.id.scoreinit_label2); |
68 | 74 | |
75 | + mContentResolver = getContentResolver(); | |
69 | 76 | Intent intent = getIntent(); |
70 | 77 | Bundle bundle = intent.getExtras(); |
71 | 78 |
@@ -74,6 +81,7 @@ | ||
74 | 81 | team1btn.setText(bundle.getString(PlayInfoEditorActivity.TEAM1_KEY)); |
75 | 82 | team2btn.setText(bundle.getString(PlayInfoEditorActivity.TEAM2_KEY)); |
76 | 83 | } |
84 | + mResultId++; | |
77 | 85 | } |
78 | 86 | |
79 | 87 | //コンテキストメニュー作成 |
@@ -182,6 +190,7 @@ | ||
182 | 190 | break; |
183 | 191 | case R.id.ok_btn: //OKボタン |
184 | 192 | //DBの登録ここでします。 |
193 | + insertDB(); | |
185 | 194 | returnIntent(RESULT_TRUE); |
186 | 195 | finish(); |
187 | 196 | break; |
@@ -192,6 +201,30 @@ | ||
192 | 201 | } |
193 | 202 | } |
194 | 203 | |
204 | + private void insertDB() { | |
205 | + int num = listView.getCount(); | |
206 | + for (int i =0; i < num; i++) { | |
207 | + PlayResultEditorListItem listItem = (PlayResultEditorListItem)adapter.getItem(i); | |
208 | + String assist = listItem.getAssist(); | |
209 | + String score = listItem.getScorer(); | |
210 | + String team = listItem.getTeam(); | |
211 | + ContentValues cv = new ContentValues(); | |
212 | + cv.put(Point.ASSIST, assist); | |
213 | + cv.put(Point.SCORER, score); | |
214 | + int teamid = 0; //チームID | |
215 | + | |
216 | + Cursor cursor = mContentResolver.query(Team.CONTENT_URI, new String[]{ | |
217 | + Team._ID}, Team.TEAM + "=?", new String[]{team}, null); | |
218 | + if(cursor.moveToFirst()){ //チーム名に対するID取り出し | |
219 | + teamid = cursor.getInt(0); | |
220 | + cursor.close(); | |
221 | + cv.put(Point.TEAMID, teamid); | |
222 | + } | |
223 | + | |
224 | + mContentResolver.insert(Point.CONTENT_URI, cv); | |
225 | + } | |
226 | + } | |
227 | + | |
195 | 228 | /** |
196 | 229 | * ヘッダの初期化処理を行います。 |
197 | 230 | */ |