数据传递到使用意图三项活动 [英] pass data to three activities using intent
问题描述
我有三个活动和流动谨信息
>> 员工
>> workDetailsTable
。我用意图
传递数据。然而,当我看到存储在 SQLite的数据
,我只能看到保存在员工
表中的值。我让 NULL
在信息
表值。为什么会出现这种情况?它是唯一能够将数据传递到两项活动只?
资讯
button.setOnClickListener(新View.OnClickListener(){
公共无效的onClick(查看为arg0){
意向意图=新意图(背景下,WorkForce.class);
A = spinner.getSelectedItem()的toString()。
intent.putExtra(一,一);
startActivity(意向);
}
});
员工
button.setOnClickListener
(
新View.OnClickListener(){
公共无效的onClick(视图v){
意向意图=新意图(背景下,WorkDetailsTable.class);
SUBCON = txt1.getText()的toString()。
startActivity(意向);
}
}
);
WorkDetailsTable
最终字符串名称= getIntent()getExtras()的getString(A)。;
最后弦乐分包商= getIntent()getExtras()的getString(转包)。;
按钮BTN1 =(按钮)findViewById(R.id.button2);
btn1.setOnClickListener(新View.OnClickListener(){
公共无效的onClick(查看为arg0){ ts.insertTimeSheet(名);
WF.insertWorkForce(分包商);
你是不是通过 SUBCON
通过意图workdetails表字符串。通过他们就像你在信息活动一样。还需要在劳动力从意图获得 A
的价值和意图传递相同的值workdetails。
所以你的code的员工会像下面。
button.setOnClickListener(新View.OnClickListener(){
公共无效的onClick(视图v){
意向意图=新意图(背景下,WorkDetailsTable.class);
SUBCON = txt1.getText()的toString()。
intent.putExtra(。一,getIntent()getExtras()的getString(一));
intent.putExtra(转包,转包);
startActivity(意向);
}
});
I have three activities and the flow should like Information
>>workForce
>>workDetailsTable
. I pass the data by using intent
. However, when I see the data stored in SQLite
, I only able to see the values saved in WorkForce
table. I getting NULL
value in Information
table. Why would this happen? It is only able to pass the data to two activities only?
Information
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent intent = new Intent(context, WorkForce.class);
a = spinner.getSelectedItem().toString();
intent.putExtra("a",a);
startActivity(intent);
}
});
WorkForce
button.setOnClickListener
(
new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(context, WorkDetailsTable.class);
subCon=txt1.getText().toString();
startActivity(intent);
}
}
);
WorkDetailsTable
final String name=getIntent().getExtras().getString("a");
final String subContractors=getIntent().getExtras().getString("subCon");
Button btn1=(Button)findViewById(R.id.button2);
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
ts.insertTimeSheet(name);
WF.insertWorkForce(subContractors);
you are not passing subCon
string through intent to workdetails table. pass them like you did in information activity. also you need to get value of a
from intent in workforce and pass the same value in intent to workdetails.
so your code for WorkForce would be like below.
button.setOnClickListener ( new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(context,WorkDetailsTable.class);
subCon=txt1.getText().toString();
intent.putExtra("a",getIntent().getExtras().getString("a"));
intent.putExtra("subCon",subCon);
startActivity(intent);
}
});
这篇关于数据传递到使用意图三项活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!