Android Sqlite数据库是否将值传递给多个表?
我已经根据需要构建了一个三sqlite表 1.登录 2.名单 3.备忘录 在我的表中,我将登录id(id)值从第一个表传递到显示id2的第二个表 现在我想把id值从表2传递到id2下的表3 我尝试使用游标的intent传递值,但没有得到任何值。它只显示零 任何人都可以从我的密码中找出错误 我的密码 1.显示第三个表详细信息的类Android Sqlite数据库是否将值传递给多个表?,android,sqlite,simplecursoradapter,Android,Sqlite,Simplecursoradapter,我已经根据需要构建了一个三sqlite表 1.登录 2.名单 3.备忘录 在我的表中,我将登录id(id)值从第一个表传递到显示id2的第二个表 现在我想把id值从表2传递到id2下的表3 我尝试使用游标的intent传递值,但没有得到任何值。它只显示零 任何人都可以从我的密码中找出错误 我的密码 1.显示第三个表详细信息的类 public class addmemo extends Activity{ EditText memtitle, content; Button add, can
public class addmemo extends Activity{
EditText memtitle, content;
Button add, cancel;
int id1;
String title;
int id;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.addmemo);
setUpViews();
//title = (EditText) findViewById(R.id.admemotit);
//content = (EditText) findViewById(R.id.addmem);
add = (Button) findViewById(R.id.addmembutton);
cancel = (Button) findViewById(R.id.canmembuttn);
cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
addmemo.this.finish();
}
});
}
private void setUpViews() {
// TODO Auto-generated method stub
memtitle = (EditText) findViewById(R.id.admemotit);
title = memtitle.getText().toString();
content = (EditText) findViewById(R.id.addmem);
Bundle extras = getIntent().getExtras();
if (extras != null) {
id=extras.getInt("id");
Log.d("idd", String.valueOf(id));
id1=extras.getInt("id1");
Log.d("idd1",String.valueOf(id1));
memtitle.setText(extras.getString("title"));
content.setText(extras.getString("content"));
Log.d("title", memtitle.getText().toString());
}
add = (Button) findViewById(R.id.addmembutton);
add.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if (memtitle.getText().length() != 0) {
AsyncTask<Object, Object, Object> saveContactTask = new AsyncTask<Object, Object, Object>() {
@Override
protected Object doInBackground(Object... params) {
saveContact();
Log.d("asd", "asd");
return null;
}
@Override
protected void onPostExecute(Object result) {
finish();
}
};
saveContactTask.execute((Object[]) null);
} else {
AlertDialog.Builder alert = new AlertDialog.Builder(
addmemo.this);
alert.setTitle("Error In Save Contact");
alert.setMessage("You need to Enter Name of the Contact");
alert.setPositiveButton("OK", null);
alert.show();
}
}
});
}
private void saveContact() {
logindatabaseadapter sqlCon = new logindatabaseadapter(this);
Log.d("asd","asd1");
if (getIntent().getExtras() == null) {
sqlCon.insertmemoentry(memtitle.getText().toString(), content.getText().toString(),
GetSet.getUserId(), GetSet.getListId());
Log.d("ti", memtitle.toString());
Log.d("co", content.toString());
Log.d("i", String.valueOf(id));
}
else {
boolean modified=true;
sqlCon.updateContact(title.getText().toString(), category.getText().toString(),
modified);
}
}}
public类addmemo扩展活动{
编辑文本、标题、内容;
按钮添加、取消;
INTID1;
字符串标题;
int-id;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.addmemo);
setupview();
//title=(EditText)findViewById(R.id.admemotit);
//content=(EditText)findViewById(R.id.addmem);
add=(按钮)findViewById(R.id.addmembutton);
cancel=(按钮)findViewById(R.id.CanMemButton);
cancel.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
//TODO自动生成的方法存根
addmemo.this.finish();
}
});
}
私有void setUpViews(){
//TODO自动生成的方法存根
memtitle=(EditText)findViewById(R.id.admemotit);
title=memtitle.getText().toString();
content=(EditText)findViewById(R.id.addmem);
Bundle extras=getIntent().getExtras();
如果(附加值!=null){
id=额外的getInt(“id”);
Log.d(“idd”,String.valueOf(id));
id1=额外的getInt(“id1”);
Log.d(“idd1”,String.valueOf(id1));
memtitle.setText(extras.getString(“title”);
setText(extras.getString(“content”);
Log.d(“title”,memtitle.getText().toString());
}
add=(按钮)findViewById(R.id.addmembutton);
add.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图arg0){
//TODO自动生成的方法存根
if(memtitle.getText().length()!=0){
AsyncTask saveContactTask=新建AsyncTask(){
@凌驾
受保护对象doInBackground(对象…参数){
saveContact();
Log.d(“asd”、“asd”);
返回null;
}
@凌驾
受保护的void onPostExecute(对象结果){
完成();
}
};
saveContactTask.execute((Object[])null;
}否则{
AlertDialog.Builder alert=新建AlertDialog.Builder(
addmemo.this);
alert.setTitle(“保存联系人时出错”);
setMessage(“您需要输入联系人的姓名”);
alert.setPositiveButton(“确定”,空);
alert.show();
}
}
});
}
私有void saveContact(){
logindatabaseadapter sqlCon=新的logindatabaseadapter(此);
日志d(“asd”、“asd1”);
if(getIntent().getExtras()==null){
sqlCon.insertmemoentry(memtitle.getText().toString(),content.getText().toString(),
GetSet.getUserId(),GetSet.getListId());
Log.d(“ti”,memtitle.toString());
Log.d(“co”,content.toString());
Log.d(“i”,String.valueOf(id));
}
否则{
布尔修改=真;
sqlCon.updateContact(title.getText().toString(),category.getText().toString(),
修改);
}
}}
2.适配器类
@Override
public void bindView(View v, final Context context, Cursor c) {
final int id = c.getInt(c.getColumnIndex(contacts.loginid1));
Log.d("id", Integer.toString(id));
final int id1 = c.getInt(c.getColumnIndex(contacts.loginid));
Log.d("id1", Integer.toString(id1));
final String title = c.getString(c.getColumnIndex(contacts.title));
final String category = c.getString(c.getColumnIndex(contacts.category));
c.moveToFirst();{
ArrayList<String> newarray = new ArrayList<String>();
newarray.add(title);
}
//curval = (TextView) v.findViewById(R.id.cursorvalue);
Cursor cur = logindatabaseadapter.remindervalues(id,id1);
if(cur!=null){
cur.moveToFirst();
str = cur.getCount();
Log.d("vaal", String.valueOf(str));
}
curval.setText(xurva + "/" + "0");
cur.close();
Cursor cur1 = logindatabaseadapter.getcursorvalues(id,id1,values);
if(cur!=null){
cur.moveToFirst();
str = cur.getCount();
Log.d("vaal", String.valueOf(str));
}
String xurva1 = String.valueOf(str);
curval = (TextView) v.findViewById(R.id.cursorvalue);
curval.setText(" "+ xurva + "/" + xurva1);
cur1.close();
ImageView iv = (ImageView) v.findViewById(R.id.photo123);
iv.setSelected(false);
// TODO Auto-generated method stub
if (category.equalsIgnoreCase("personal")) {
iv.setImageResource(R.drawable.ic_launcher);
} else if (category.equalsIgnoreCase("Entertainment")) {
iv.setImageResource(R.drawable.ic_launcher);
} else if (category.equalsIgnoreCase("Official")) {
iv.setImageResource(R.drawable.ic_launcher);
} else if (category.equalsIgnoreCase("Health")) {
iv.setImageResource(R.drawable.ic_launcher);
} else if (category.equalsIgnoreCase("Friends")) {
iv.setImageResource(R.drawable.ic_launcher);
} else if (category.equalsIgnoreCase("Travel")) {
iv.setImageResource(R.drawable.ic_launcher);
} else if (category.equalsIgnoreCase("Sports")) {
iv.setImageResource(R.drawable.ic_launcher);
} else if (category.equalsIgnoreCase("Education")) {
iv.setImageResource(R.drawable.ic_launcher);
} else if (category.equalsIgnoreCase("Birthday")) {
iv.setImageResource(R.drawable.ic_launcher);
} else if (category.equalsIgnoreCase("Miscellaneous")) {
iv.setImageResource(R.drawable.ic_launcher);
} else if (category.equalsIgnoreCase("Meeting")) {
iv.setImageResource(R.drawable.ic_launcher);
} else {
iv.setImageResource(R.drawable.ic_launcher);
}
TextView ttitle = (TextView) v.findViewById(R.id.title);
ttitle.setSelected(false);
RelativeLayout layout = (RelativeLayout) v
.findViewById(R.id.relativeLayout1);
if (col % 2 != 1) {
layout.setBackgroundColor(0xFFC1E7FF);
} else {
layout.setBackgroundColor(0xFF98D4FA);
} col++; ttitle.setText(title);
ImageView timage = (ImageView) v.findViewById(R.id.photo123);
LinearLayout layou1 = (LinearLayout) v.findViewById(R.id.linearali1);
if (col1 % 2 != 1) {
layou1.setBackgroundColor(0xFF87CEFA);
} else {
layou1.setBackgroundColor(0xFF6495ED);
}
col1++;
final logindatabaseadapter sqlCon = new logindatabaseadapter(context);
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, memo.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("id",id );
Log.d("ci", String.valueOf(id));
intent.putExtra("id1", id1);
Log.d("ci1", String.valueOf(id1));
context.startActivity(intent);
}
});
v.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
// Toast.makeText(context, "U Long Clicked..", 5000).show();
//return true;
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);
// set title
alertDialogBuilder.setTitle("Delete");
// set dialog message
alertDialogBuilder
.setMessage("Are you sure you want to delete")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id1) {
// if this button is clicked, close
// current activity
//sqlCon.deleteContact(id);
//Intent intent = new Intent(context, MyContactsActivitynew.class)
// .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//context.startActivity(intent);
dialog.dismiss();
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
return true;
}
});
}
}
@覆盖
public void bindView(视图v,最终上下文,光标c){
final int id=c.getInt(c.getColumnIndex(contacts.loginid1));
Log.d(“id”,Integer.toString(id));
final int id1=c.getInt(c.getColumnIndex(contacts.loginid));
Log.d(“id1”,Integer.toString(id1));
最终字符串标题=c.getString(c.getColumnIndex(contacts.title));
最终字符串类别=c.getString(c.getColumnIndex(contacts.category));
c、 moveToFirst(){
ArrayList newarray=新ArrayList();
newarray.add(title);
}
//curval=(TextView)v.findViewById(R.id.cursorvalue);
cursorcur cur=loginDataBaaseadAdapter.ReminderValue(id,id1);
如果(cur!=null){
cur.moveToFirst();
str=cur.getCount();
Log.d(“vaal”,String.valueOf(str));
}
curval.setText(xurva+“/”+“0”);
cur.close();
Cursor cur1=logindatabaseadapter.getcursorvalues(id,id1,values);
如果(cur!=null){
cur.moveToFirst();
str=cur.getCount();
Log.d(“vaal”,String.valueOf(str));
}
String xurva1=String.valueOf(str);
curval=(TextView)v.findViewById(R.id.cursorvalue);
曲线setText(“+xurva+”/“+xurva 1”);
cur1.close();
ImageView iv=(ImageView)v.findViewById(R.id.photo123);
iv.1(假);
//TODO自动生成的方法存根
if(同等信号情况(“个人”)类别){
iv.setImageResource(R.drawable.ic_发射器);
}else if(类别相等信号(“娱乐”)){
iv.setImageResource(R.drawable.ic_发射器);
}else if(类别同等信号(“官方”)){
iv.setImageResource(R.drawable.ic_发射器);
}else if(类别等信号(“健康”)){
iv.setImageResource(R.drawable.ic_发射器);
}else if(类别.相等信号(“朋友”)){
iv.setImageResource(R.drawable.ic_发射器);
}else if(类别等信号(“旅行”)){
iv.setImageResource(R.drawable.ic_发射器);
}else if(类别.相等信号情况(“运动”)){
iv.setImageResource(R.drawable.ic_发射器);
}else if(类别、同等信号(“教育”)){
iv.setImageResource(R.drawable.ic_发射器);
}else if(类别.相等信号(“生日”)){
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, memo.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("id",id );
Log.d("ci", String.valueOf(id));
intent.putExtra("id1", id1);
Log.d("ci1", String.valueOf(id1));
context.startActivity(intent);
}
});
public class addmemo extends Activity