Android studio 在Android Studio中将内容值从一个活动传递到另一个活动

Android studio 在Android Studio中将内容值从一个活动传递到另一个活动,android-studio,Android Studio,活动1 private Cursor model = null; private ClientAdapter adapter = null; private ClientHelper helper = null; private SharedPreferences prefs = null; private ArrayAdapter<String> adapters; private ArrayAdapter<String> adaptera; private Strin

活动1

private Cursor model = null;
private ClientAdapter adapter = null;
private ClientHelper helper = null;
private SharedPreferences prefs = null;
private ArrayAdapter<String> adapters;
private ArrayAdapter<String> adaptera;
private String[] available_locations;
private String[] selected_locations;
private ListView list1;
private ListView list2;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.locations);

    list1 = (ListView) findViewById(R.id.available_locations);
    list2 = (ListView) findViewById(R.id.selected_locations);
    available_locations = getIntent().getStringExtra("List");
    .....
private Cursor model=null;
专用客户端适配器=null;
private ClientHelper helper=null;
私有SharedReferences prefs=null;
专用阵列适配器;
私有阵列适配器;
私有字符串[]可用位置;
私有字符串[]所选位置;
私有列表视图列表1;
私有列表视图列表2;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(右布局位置);
list1=(ListView)findViewById(R.id.available\u位置);
list2=(ListView)findViewById(R.id.所选位置);
可用位置=getIntent().getStringExtra(“列表”);
.....
活动2

....
public String getID(Cursor c) {
    return (c.getString(0));
}

public String getclientName(Cursor c) {
    return (c.getString(1));
}

public String getAddress(Cursor c) {
    return (c.getString(2));
}

public String getTelephone(Cursor c) {
    return (c.getString(3));
}

public String getCuisineType(Cursor c) {
    return (c.getString(4));
}

public double getLatitude(Cursor c) {
    return (c.getDouble(5));
}

public double getLongitude(Cursor c) {
    return (c.getDouble(6));
}

public ArrayList<String> getclient;
getclient.add("clientName");
getclient.add("Address");
getclient.add("Telephone");
getclient.add("cuisineType");
getclient.add("lat");
getclient.add("lon");
public Intent intenti;
intenti = new Intent(ClientHelper.this, SetDestination.class);
intenti.putExtra("List", getclient);
startactivity(intenti);
。。。。
公共字符串getID(游标c){
返回值(c.getString(0));
}
公共字符串getclientName(游标c){
返回(c.getString(1));
}
公共字符串getAddress(游标c){
返回(c.getString(2));
}
公用字符串getTelephone(光标c){
返回(c.getString(3));
}
公共字符串getCuisineType(光标c){
返回(c.getString(4));
}
公共双纬度(光标c){
返回(c.getDouble(5));
}
公共双精度经度(光标c){
返回(c.getDouble(6));
}
公共arraylistgetclient;
getclient.add(“clientName”);
getclient.add(“地址”);
getclient.add(“电话”);
getclient.add(“cuisineType”);
getclient.add(“lat”);
getclient.add(“lon”);
公共意图;
intenti=新意图(ClientHelper.this、SetDestination.class);
intenti.putExtra(“列表”,getclient);
星触觉(intenti);
如何将信息从Activity2传递到Activity1


我想做一个Listview,在这里我可以从我已经添加的列表中选择客户端(因此在activity1中有两个活动list1和list2)

Use可以使用捆绑包将数据从一个活动传递到另一个活动

首先让对象可包裹。你可以使用android studio中的parcelable插件来实现这一点

例如。 Intent Intent=新的Intent(getActivity(),targetclassname.class); HomeScreenda HomeScreenda=新的HomeScreenda();//Pojo类 意向书。putExtra(“分类”,HomeScreenda); 星触觉(意向)

{
//Pojo类`在此处输入代码`
公共类HomeScreenda实现可包裹{
私有字符串路径;
私有字符串图像标题;
公共字符串getImagePath(){
返回图像路径;
}
公共void setImagePath(字符串imagePath){
this.imagePath=imagePath;
}
公共字符串getImageTitle(){
返回图像标题;
}
public void setImageTitle(字符串imageTitle){
this.imageTitle=imageTitle;
}
@凌驾
公共int描述内容(){
返回0;
}
@凌驾
公共无效写入包裹(包裹目的地,内部标志){
dest.writeString(this.imagePath);
dest.writeString(此.imageTitle);
}
公共住宅区(){
}
受保护住宅区(地块内){
this.imagePath=in.readString();
this.imageTitle=in.readString();
}
public static final Parcelable.Creator=新建Parcelable.Creator(){
公共HomeScreenda createFromParcel(地块源){
返回新的HomeScreenda(来源);
}
公共HomeScreenda[]新数组(整数大小){
返回新的HomeScreenda[尺寸];
}
};
}

{
//Pojo Class`enter code here`
public class HomeScreenData implements Parcelable {
private String imagePath;
private String imageTitle;

public String getImagePath() {
    return imagePath;
}

public void setImagePath(String imagePath) {
    this.imagePath = imagePath;
}

public String getImageTitle() {
    return imageTitle;
}

public void setImageTitle(String imageTitle) {
    this.imageTitle = imageTitle;
}


@Override
public int describeContents() {
    return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeString(this.imagePath);
    dest.writeString(this.imageTitle);
}

public HomeScreenData() {
}

protected HomeScreenData(Parcel in) {
    this.imagePath = in.readString();
    this.imageTitle = in.readString();
}

public static final Parcelable.Creator<HomeScreenData> CREATOR = new Parcelable.Creator<HomeScreenData>() {
    public HomeScreenData createFromParcel(Parcel source) {
        return new HomeScreenData(source);
    }

    public HomeScreenData[] newArray(int size) {
        return new HomeScreenData[size];
    }
};