今天,上了口语,数据库,python,口语上的很开心,数据库上的很恶心,报告不会写,怎么操作用户,服务器,python课上考试,下午对项目进行更改,主要改动的是数据传输,将数据线传输变得更为简单直接,主要多亏了提供的返回上一个activity方法,对于项目的优化更好了。
首先,源fragment内添加内容
Button myButton = (Button) getActivity().findViewById(R.id.Add_Button);
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getActivity(), Add.class);
Bundle bundle = new Bundle();
bundle.putInt("User_id",User_id);
intent.putExtras(bundle);
//2023.5.16更改
startActivityForResult(intent,1);
// startActivity(intent);
}
});
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1)
{
if(resultCode == RESULT_OK)
{
int flag = data.getIntExtra("already_Login",-1);
// System.out.println("收到了 == " + data.getIntExtra("already_Login",-1));
if(flag == -1)
{
Toast.makeText(getContext(), "出错了,主人", Toast.LENGTH_SHORT).show();
}else
{
Toast.makeText(getContext(), "收到了,主人", Toast.LENGTH_SHORT).show();
User_id = flag;
System.out.println("User_id " + User_id);
simpleAdapter = new SimpleAdapter(getActivity(),getData(),R.layout.my_menu,new String[]{"type","money"},new int[]{R.id.myMenu_type,R.id.myMenu_money});
listView.setAdapter(simpleAdapter);
// Intent intent1 = new Intent(getActivity(), Menu.class);
// Bundle bundle2 = new Bundle();
// bundle2.putInt("User_id",flag);
// intent1.putExtra("thesame",bundle2);
// intent1.putExtras(bundle2);
// startActivity(intent1);
// Intent intent = new Intent(getActivity(), Menu.class);
// //更新操作 2023.5.16
// System.out.println("flag === " + flag);
// intent.putExtra("flag",flag);
// startActivity(intent);
// //setResult(RESULT_OK,intent);
// //finish();
}
}
}
}
跳转activity的添加内容
public void onClick(View view) {
float Comsumermoney;
String Comsumertype;
String Comsumerresourse;
//
Comsumermoney = Float.parseFloat(ConsumeMoneyEdit.getText().toString());
Comsumertype = type;
Comsumerresourse = ConsumeSourseEdit.getText().toString();
System.out.println("ConsumeMoneyEdit = " + ConsumeMoneyEdit.getText().toString());
System.out.println("ConsumeTimeEdit = " + Consumerdate);
System.out.println("ConsumeSourseEdit = " + ConsumeSourseEdit.getText().toString());
System.out.println("Comsumer = " + comsumer);
System.out.println("type = " + type);
System.out.println("----------------------------------");
Consume consume = new Consume(Consumerdate,Comsumermoney,Comsumertype,Comsumerresourse,comsumer);
//数据库
project helper = new project(Add.this);
sqLiteDatabase = helper.getReadableDatabase();
helper.AddConsume(sqLiteDatabase,consume);
Intent intent = new Intent(Add.this, HomeFragment.class);
//更新操作 2023.5.16
System.out.println("comsumer === " + comsumer);
intent.putExtra("already_Login",comsumer);
setResult(RESULT_OK,intent);
/* Bundle bundle = new Bundle();
System.out.println("already_Login = " + comsumer);
bundle.putInt("already_Login",comsumer);
intent.putExtra("AfterAdd",bundle);
startActivity(intent);
System.out.println("添加界面的销毁");
*/
finish();
}
标签:Intent,16,System,intent,2023,println,new,随笔,out From: https://www.cnblogs.com/JIANGzihao0222/p/17407191.html