O’zbekiston respublikasi oliy va o’rta maxsus ta’lim vazirligi buxoro davlat universiteti




Download 0,95 Mb.
Pdf ko'rish
bet11/12
Sana28.07.2024
Hajmi0,95 Mb.
#268859
1   ...   4   5   6   7   8   9   10   11   12
Bog'liq
android operatsion tizimida dars jadvali yaratish

EditActivity.java 
package com.example.dj; 
import android.os.Bundle; 
import android.app.Activity; 
import android.database.Cursor; 
import android.text.TextUtils; 


54 
import android.util.Log; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.Spinner; 
import android.widget.Toast; 
public class EditActivity extends Activity { 
private EditText mTitleText; 
private EditText mBodyText; 
private Long mRowId; 
private ToDoDatabase mDbHelper; 
private Spinner mCategory; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
mDbHelper = new ToDoDatabase(this); 
setContentView(R.layout.edit_main); 
mCategory = (Spinner) findViewById(R.id.category); 
mTitleText = (EditText) findViewById(R.id.todo_edit_summary); 
mBodyText = (EditText) findViewById(R.id.todo_edit_description); 
Button confirmButton = (Button) findViewById(R.id.todo_edit_button); 
mRowId = null; 
Bundle extras = getIntent().getExtras(); 
mRowId = (savedInstanceState == null) ? null 
: (Long) savedInstanceState 
.getSerializable(ToDoDatabase.COLUMN_ID); 
if (extras != null) { 
mRowId = extras.getLong(ToDoDatabase.COLUMN_ID); 

populateFields(); 
confirmButton.setOnClickListener(new View.OnClickListener() { 
public void onClick(View view) { 
if (TextUtils.isEmpty(mTitleText.getText().toString())) { 
Toast.makeText(EditActivity.this, 
"Berilganlar 
kiritilmagan", 
Toast.LENGTH_LONG).show(); 
} else { 
saveState(); 
setResult(RESULT_OK); 
finish(); 




55 
}); 

private void populateFields() { 
if (mRowId != null) { 
Cursor todo = mDbHelper.getTodo(mRowId); 
startManagingCursor(todo); 
String category = todo.getString(todo 
.getColumnIndexOrThrow(ToDoDatabase.COLUMN_CATEGORY)); 
for (int i = 0; i < mCategory.getCount(); i++) { 
String s = (String) mCategory.getItemAtPosition(i); 
Log.e(null, s + " " + category); 
if (s.equalsIgnoreCase(category)) { 
mCategory.setSelection(i); 


mTitleText.setText(todo.getString(todo 
.getColumnIndexOrThrow(ToDoDatabase.COLUMN_SUMMARY))); 
mBodyText.setText(todo.getString(todo 
.getColumnIndexOrThrow(ToDoDatabase.COLUMN_DESCRIPTION))); 
todo.close(); 


@Override 
protected void onSaveInstanceState(Bundle outState) { 
super.onSaveInstanceState(outState); 
//saveState(); 
//outState.putSerializable(ToDoDatabase.COLUMN_ID, mRowId); 

@Override 
protected void onPause() { 
super.onPause(); 
//saveState(); 

@Override 
protected void onResume() { 
super.onResume(); 
populateFields(); 

private void saveState() { 
String category = (String) mCategory.getSelectedItem(); 
String summary = mTitleText.getText().toString(); 
String description = mBodyText.getText().toString(); 
if (description.length() == 0 && summary.length() == 0) { 
return; 



56 
if (mRowId == null) { 
long id = mDbHelper.createNewTodo(category, summary, description); 
if (id > 0) { 
mRowId = id; 

} else { 
mDbHelper.updateTodo(mRowId, category, summary, description); 




Download 0,95 Mb.
1   ...   4   5   6   7   8   9   10   11   12




Download 0,95 Mb.
Pdf ko'rish

Bosh sahifa
Aloqalar

    Bosh sahifa



O’zbekiston respublikasi oliy va o’rta maxsus ta’lim vazirligi buxoro davlat universiteti

Download 0,95 Mb.
Pdf ko'rish