我會告訴你我的應用程序的這部分的目的。我有一個SQLite dB有3列。首先是「數量」,其次是「產品」,第三是「價格」。那麼,我想要做的就是獲得整個dB並通過電子郵件發送。 這就是我現在所擁有的:SQLite Android。管理數據
public class Visual extends Activity {
TextView tv;
Button sqlGetInfo;
long l ;
long b=1;
int c,i;
String returnedQuantity ,returnedProduct ,returnedPrice;
String[] filas;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.visual);
tv = (TextView) findViewById(R.id.tvSQLinfo);
sqlGetInfo = (Button) findViewById(R.id.EnviarPedido);
SQLManager info = new SQLManager(this);
info.open();
String data= info.getData();
info.close();
tv.setText(data);
到這裏,我的代碼工作正常,它顯示在TextView的數據。這是問題。我的dB最多有15行。我想要做的是將每行存儲在一個字符串數組(位置)的位置。第一行=絲狀(0),第二行=絲狀(1)...以便能夠將該陣列傳遞到另一活動。如果數組少於15行,我認爲它會給出一個例外。所以現在是時候打開其他活動了。
final SQLManager hon = new SQLManager(this);
sqlGetInfo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
for (i = 1; i < 15; i++) {
try{
l = (long) i;
hon.open();
returnedQuantity = hon.getQuantity(l);
returnedProduct = hon.getProduct(l);
returnedPrice = hon.getPrice(l);
hon.close();
c=(int)(l-b);
filas[c]="" + returnedQuantity+" "+ returnedProduct+" "+ returnedPrice + "\n";
}catch (Exception e){
i = 16;
l = (long) i;
Intent abrePedidos = new Intent(Visual.this, Pedidos.class);
abrePedidos.putExtra("pedidoCompleto", filas);
startActivity(abrePedidos);
}
}
}
});
}
}
另一項活動是這樣的:
public class Pedidos extends Activity {
String[] filas;
long numProd;
boolean end;
int i;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
filas=getIntent().getStringArrayExtra("pedidoCompleto");
String subject = "Pedido a Domicilio";
String cabecera = "Unid. Producto Precio\n\n";
String[] emails = {"[email protected]"};
String message = cabecera + filas;
Intent emailIntent = new Intent (android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emails);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
emailIntent.setType("plain/text");
startActivity(emailIntent);
}
}
我得到了我的電子郵件的消息是「空」。
如果我正確地找到了'filas',則在此行上爲null:'String message = cabecera + filas;'?或者你通過電子郵件引用了什麼? – 2012-03-03 12:33:38
當通過startActivity調用emailIntent時,移動設備上的電子郵件應用程序(本例中爲gmail)顯示:電子郵件,主題和消息。什麼是零花絲,而不是cabecera。 – Aldridge1991 2012-03-03 12:47:37