[android-developers] how to show the database(ListView) from another activity

2012-08-30 Thread MY Anggara
hi guys, i'm just a newbie in android world.
i got a problem about to show my database as a ListView from another 
activity.

1. i have ActivityA that i use to insert a value.
and in this activity i use to send data to ActivityB.

2. i have ActivityB as a ListView that show a database of input data from 
ActivityB

but i have a problem how to show the database in ListView.
i'll attach the code, and i hope there's/re help for me.
Thanks.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en//this is ActivityA
package com.anggara.latih_howmuch2;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
 
public class add_income extends Activity {
// Initializing variables
EditText inputAmount;
EditText inputDesc;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
 
inputAmount = (EditText) findViewById(R.id.amount);
inputDesc = (EditText) findViewById(R.id.desc);
Button btnAddIncome = (Button) findViewById(R.id.btnAddIncome);
 
//Listening to button event
btnAddIncome.setOnClickListener(new View.OnClickListener() {
 
public void onClick(View arg0) {
//Starting a new Intent
Intent addIncome = new Intent(getApplicationContext(), 
CashScreen.class);
 
//Sending data to another Activity
addIncome.putExtra(amount, inputAmount.getText().toString());
addIncome.putExtra(desc, inputDesc.getText().toString());
 
Log.e(n, inputAmount.getText()+.+ inputDesc.getText());
 
startActivity(addIncome);
 
}
});
}
}//this is ActivityB
package com.anggara.latih_howmuch2;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.SimpleCursorAdapter;

public class CashScreen extends Activity {
mySqlHelper dbHelper;
private EditText ed_amount;
private EditText ed_desc;
protected Cursor cursor;
protected ListAdapter adapter;
protected ListView numberList;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.screen2);

//TextView txtAmount = (TextView) findViewById(R.id.txtAmount);
//TextView txtDesc = (TextView) findViewById(R.id.txtDesc);
Button btnClose = (Button) findViewById(R.id.btnClose);

Intent i = getIntent();
// Receiving the Data
String amount = i.getStringExtra(amount);
String desc = i.getStringExtra(desc);
Log.e(Second Screen, amount + . + desc);

//this.ed_amount = (EditText) this.findViewById(R.id.amount);
  //  this.ed_desc = (EditText) this.findViewById(R.id.desc);
this.numberList = (ListView) this.findViewById(R.id.ListView01);
dbHelper = new mySqlHelper(this);
numberList.setSelected(true);
numberList.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView? arg0, View arg1, int 
arg2, long arg3) {
SQLiteDatabase db = dbHelper.getReadableDatabase();
cursor = db.rawQuery(SELECT * FROM data, null);
cursor.moveToPosition(arg2);
amount.setText(cursor.getString(1));
desc.setText(cursor.getString(2));
int id = cursor.getInt(0);
}});
view();
btnClose.setOnClickListener(new View.OnClickListener() {
 
public void onClick(View arg0) {
//Closing SecondScreen Activity
finish();
}
});
}
private void addData(String amount, String desc){
SQLiteDatabase db = dbHelper.getWritableDatabase();
try{db.execSQL(insert into + mySqlHelper.TABLE + values(null, 
'+amount+','+desc+'));
}
catch(Exception e)

[android-developers] how to show the database(ListView) from another activity

2012-08-30 Thread Jason Sesso
Did you bundle the data from A to send it to  B?

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en