это мой полный код! :
import java.util.Arrays;
import datenbank.test.R.id;
импорт android.R.layout;
импорт android.app.Activity;
import android.content.SharedPreferences.Editor;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
импорт android.os.Bundle;
импорт android.view.Menu;
импорт android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.EditText;
импорт android.widget.Spinner;
import android.widget.AbsSpinner;
импорт android.widget.Toast;
открытый класс Projects_new extends Activity {
SQLiteDatabase myDB = null;
static final int MENU_INSERT_PROJECTS = 0;
static final int MENU_UPDATE_PROJECTS = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(layout.activity_list_item);
Spinner s1 = (Spinner) findViewById(R.id.PROJECTS_NEW);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this,
(MENU_INSERT_PROJECTS),
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s1.setAdapter(adapter);
if(getIntent().hasExtra("id") == true) {
long l = getIntent().getExtras().getLong("id");
myDB = this.openOrCreateDatabase(datenbank.MY_DB_NAME, MODE_PRIVATE, null);
Cursor myCursor = myDB.rawQuery("SELECT name,comment, customer_project, booking_details, editable FROM" +
datenbank.MY_DB_TABLE + "WHERE _id = "+l+";", null);
startManagingCursor(myCursor);
int ColumnName = myCursor.getColumnIndex("name"); //Name
int ColumnComment = myCursor.getColumnIndex("Comment"); //Comment
int ColumnCustomer_Project = myCursor.getColumnIndex ("Customer-Project?");//ist es für customer oder intern
int ColumnBooking_Details = myCursor.getColumnIndex("Details"); //details
int ColumnEditable = myCursor.getColumnIndex("Editable?"); //bearbeiten ja oder nein
if (myCursor != null) {
if (myCursor != null) {
EditText eName = (EditText)findViewById(R.id.PROJECTS_NEW);
eName.setText(myCursor.getString(ColumnName));
EditText eComment = (EditText)findViewById(R.id.PROJECTS_NEW);
eComment.setText(myCursor.getString(ColumnComment));
EditText eCustomer_Project = (EditText)findViewById(R.id.PROJECTS_NEW);
eCustomer_Project.setText(myCursor.getString(ColumnCustomer_Project));
Spinner sBooking_Details = (Spinner)findViewById(R.id.PROJECTS_NEW);
sBooking_Details.setSelection(myCursor.getInt(ColumnBooking_Details), true);
EditText eEditable = (EditText)findViewById(R.id.PROJECTS_NEW);
eEditable.setText(myCursor.getString(ColumnEditable));
}
}}
}
private void setContentView(Class<layout> class1) {
// TODO Auto-generated method stub
}
private EditText findViewById(id id) {
// TODO Auto-generated method stub
return null;
}
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
if(getIntent().hasExtra("id")==true)
{
menu.add(0, MENU_UPDATE_PROJECTS, 0, R.string.MENU_PROJECTS)
.setShortcut('1','s')
.setIcon(android.R.drawable.ic_menu_save);
}
else
{
menu.add(0, MENU_INSERT_PROJECTS, 0, R.string.MENU_PROJECTS)
.setShortcut('1','s')
.setIcon(android.R.drawable.ic_menu_save);
}
return true;
}
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()) {
case MENU_INSERT_PROJECTS:
EditText Name = (EditText)findViewById(R.id.ed_Name);
EditText Comment = (EditText)findViewById(R.id.ed_Comment);
EditText CustomerProject = (EditText)findViewById(R.id.ed_CustomerProject);
EditText BookingDetails = (EditText)findViewById(R.id.ed_BookingDetails);
Spinner Editable = (Spinner)findViewById(R.id.cb_Editable);
int i = Editable.getSelectedItemPosition();
if(Name.length()!=0){
myDB = this.openOrCreateDatabase(datenbank.MY_DB_NAME,
MODE_PRIVATE, null);
}
//Projekt-Daten updaten (UPDATE)
if(getIntent().hasExtra("id") == true)
{
long l = getIntent().getExtras().getLong("id");
myDB.execSQL("UPDATE "+datenbank.MY_DB_TABLE+" SET "+
"name = '"+Name.getText().toString()+"', "+
"Comment = '"+Comment.getText().toString()+"', "+
"BookingDetails ='"+BookingDetails.getText().toString()+"', "+
"Editable ='"+i+"', "+
"CustomerProject = '"+CustomerProject.getText().toString()+"' "+
"WHERE _id = "+l+";");
}
//Neues Projekt in Datenbank speichern (INSERT)
else
{
myDB.execSQL("INSERT INTO" +datenbank.MY_DB_TABLE +"
(Name,
Comment,
BookingDetails,
Editable,
CustomerProject)
+"VALUES ('"+Name.getText().toString()+"',"+
"'"+Comment.getText().toString()+"',"+
"'"+BookingDetails.getText().toString()+"',"+
"'"+i+"',"+"'"+CustomerProject.getText().toString()+"');");
}
finish();
return true;
}
else
{
Toast toast = Toast.makeText(this, "Please enter a name for the new Project!",
Toast.LENGTH_SHORT);
toast.show();
}
return false;
}
}