我是android的初学者,分配一个任务。如何将以下数据存储在数组列表中,并将其显示在另一个活动中…例如:shafishapo密码24请看下面的图片并帮助我。此处输入图像描述
你需要像这样使用intent传递数据
Intent intent = new Intent(Search.this, Details.class);
intent.putExtra("cost", item.getCost()+"");
startActivity(intent);
,在另一个活动中,你可以使用get extra
获取这些值Intent intent = getIntent();
String id = intent.getStringExtra("cost");
尝试使用共享首选项。优点:1. 你可以检查这个人是否已经登录了。2. 你可以在应用程序中的任何时间点检索这些数据。3.你可以启用自动备份,并包括共享偏好,当用户在Google play中从相同帐户重新安装应用程序时,可以帮助你获得相同的数据。还有更多
你可以使用intent传递数据给其他activity:
String name,surname, pass, age;
name = edtName.getText().toString();
surname = edtSurname.getText().toString();
pass = edtPass.getText().toString();
age = edtAge.getText().toString();
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("name", name);
intent.putExtra("sname", surname);
intent.putExtra("pass", pass);
intent.putExtra("age", age);
startActivity(intent);
finish();
and in the mainActivity get like this:
Intent intent = getIntent();
String name = intent.getStringExtra("name");
String surname = intent.getStringExtra("surname");
使用此代码注册按钮点击侦听器
ArrayList al = new ArrayList();
// add elements to the array list
al.add(name, username,password,age);
//passing arraylist from MainActivity to Second Actiivty
Intent intent = new Intent(MainActivity.this, Second.class);
intent.putExtra("array_list", arr);
startActivity(intent);
在第二个活动中获取数据使用这个
ArrayList<String> fetchList= new ArrayList<String>();
fetchList= getIntent().getStringArrayListExtra("array_list");