I have constructed a three sqlite table according to my need.
1.login
2.list
3.memo
In my table i am passing the login id(id) value from 1st table to second table showing id2.
now i want to pass the id value from table 2nd to table three under id2.
I tried by passing the value using intent from cursor, but i am not getting any values. Its showing only zero.
Anyone can find out the mistake from my codes.
my codes
1.class showing the details of third table
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);
}
}}
2.adapter class
@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;
}
});
}
}
Thanks in advance.
In your adapter class you are passing to the class name memo.class
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);
}
});
and you are getting those bundle values in some other class
public class addmemo extends Activity
better you can pass those bundle values to the memo.class and using shared preference u can pass the values to your addmemo class.