I want to pass the data from one activity to other activity listview.. here i have, First Activity-listview SecondActivity-some edittextboxes(when i click the first activity listview that id related details are fetched from database and set in the edittextboxes in second activity) ThirdActivity-one listview(when i click the button in second activity i want to move the current data only to ThirdActivity Listview). Here my problem is All the data in firstactivity listview is also displayed in third activity..can anyone help me to solve this...i am new in android..
SecondActivity:
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
accountId = this.getIntent().getStringExtra("accountid");
Log.v("one",accountId);
db=new databaseone(getApplicationContext());
Cursor cur=null;
cur=db.viewdata(accountId);
// cur = db.query(db.TABLE_NAME, null,
//" id = ?", new String[] { accountId }, null, null, null);
//startManagingCursor(accounts);
if (cur.moveToFirst()) {
// update view
cheqgiven.setText(cur.getString(cur
.getColumnIndex("cheqgiven")));
cheqamt.setText(cur.getString(cur
.getColumnIndex("cheqamt")));
cheqdate.setText(cur.getString(cur
.getColumnIndex("cheqdate")));
cheqno.setText(cur.getString(cur
.getColumnIndex("cheqno")));
remarks.setText(cur.getString(cur
.getColumnIndex("remarks")));
}
//while(cur.moveToNext());{
cur.close();
db.close();
}
public void returned(View v){
Intent intent = new Intent(getApplicationContext(), Returned.class);
intent.putExtra("in", accountId);
startActivity(intent);
}
ThirdActivity:
public class Returned extends Activity {
String chequeid;
ListView lv;
ArrayList<Map<String, String>> lv2;
databaseone db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.returned);
lv=(ListView) this.findViewById(R.id.listCheque2);
lv2 = new ArrayList<Map<String, String>>();
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
chequeid = this.getIntent().getStringExtra("in");
lv2.removeAll(lv2);
db=new databaseone(getApplicationContext());
Cursor c=null;
//array=new ArrayList<String>();
c=db.viewdata(chequeid);
while (c.moveToNext()) {
LinkedHashMap<String, String> tran = new LinkedHashMap<String, String>();
String n=c.getString(c.getColumnIndex("id"));
String p=c.getString(c.getColumnIndex("cheqgiven"));
String a=c.getString(c.getColumnIndex("cheqamt"));
tran.put("id", n);
tran.put("cheqgiven", p);
tran.put("cheqamt", a);
lv2.add(tran);
}
c.close();
db.close();
SimpleAdapter adapter = new SimpleAdapter(this, lv2,
R.layout.chequelist, new String[] { "id",
"cheqgiven","cheqamt" }, new int[] { R.id.textAccNo, R.id.textName,R.id.textTransType});
lv.setAdapter(adapter);
}
Database:
public Cursor viewdata(String acct) {
// TODO Auto-generated method stub
sdb = this.getReadableDatabase();
String where = (acct == null) ? "" : " where id = " + acct;
Cursor c=sdb.rawQuery("select * from " + TABLE_NAME + where, null);
return c;
}
FirstActivity:
public class PendingForPayment extends Activity {
//ListView lv;
String accountId;
ListView lv;
//TextView tv;
//String tv1;
//String cheqgiven1,amount1;
//ArrayList<String> array;
ArrayList<Map<String, String>> lv2;
databaseone db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pending_for_payment);
//accNo= this.getIntent().getStringExtra("accnum");
//Name= this.getIntent().getStringExtra("name");
//tv=(TextView)findViewById(R.id.textAccNo);
lv=(ListView) this.findViewById(R.id.listCheque);
lv2 = new ArrayList<Map<String, String>>();
lv.setOnItemClickListener( new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View selectedView, int arg2,long arg3) {
TextView textAccountId = (TextView) selectedView.findViewById(R.id.textAccNo);
//Log.d("Accounts", "Selected Account Id : " + textAccountId.getText().toString());
Intent intent = new Intent(getApplicationContext(), Marking.class);
//tv1=tv.getText().toString();
intent.putExtra("accountid", lv2 .get(arg2).get("id"));
//intent.putExtra("accountid", textAccountId.getText().toString());
//Log.v("1", "entered");
//intent.putExtra("accountid",textAccountId);
startActivity(intent);
}
});
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
lv2.removeAll(lv2);
db=new databaseone(getApplicationContext());
Cursor c=null;
c=db.viewdata(accountId);
while (c.moveToNext()) {
LinkedHashMap<String, String> tran = new LinkedHashMap<String, String>();
String n=c.getString(c.getColumnIndex("id"));
String p=c.getString(c.getColumnIndex("cheqgiven"));
String a=c.getString(c.getColumnIndex("cheqamt"));
tran.put("id", n);
tran.put("cheqgiven", p);
tran.put("cheqamt", a);
lv2.add(tran);
}
c.close();
db.close();
SimpleAdapter adapter = new SimpleAdapter(this, lv2,
R.layout.chequelist, new String[] { "id",
"cheqgiven","cheqamt" }, new int[] { R.id.textAccNo, R.id.textName,R.id.textTransType});
lv.setAdapter(adapter);
} }