请问要怎么样通过新activity的返回值修改gridview中各个item的内容呢?

package com.example.hasee.myapplication;

import android.arch.core.internal.SafeIterableMap;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends AppCompatActivity {
GridView gridView;
private int clickTemp = -1;
//标识选择的Item
SimpleAdapter simpleAdapter;
List>list;
String add_Title="",add_Context="";
Mapmap;
Button button;
int count;
final String[] name=new String[]{"语文","语文","语文","语文","语文","语文","语文","语文","语文","语文","语文","语文","语文","语文","语文","语文","语文"};
final String[] location=new String[]{"六教","六教","六教","六教","六教","六教","六教","六教","六教","六教","六教","六教","六教","六教","六教","六教","六教"};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    gridView=findViewById(R.id.My_gridview);
    list=new ArrayList<>();
    for(int i=0;i<name.length;i++)
    {
        map=new HashMap<>();
        map.put("001",name[i]);
        map.put("002",location[i]);
        list.add(map);
    }
    simpleAdapter=new SimpleAdapter(MainActivity.this,list,R.layout.gridview_item,new String[]{"001","002"},new int[]{R.id.textView,R.id.textView2});
    gridView.setAdapter(simpleAdapter);
    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            startActivityForResult(new Intent(MainActivity.this,Main2Activity.class),0x01);
            count=position;
        }

    });
}



@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 0x01 && resultCode == 0x07) {
        add_Title = data.getStringExtra("003");
        add_Context = data.getStringExtra("004");
        name[count]=add_Title;
        location[count]=add_Context;
        Toast.makeText(MainActivity.this,name[count],Toast.LENGTH_SHORT).show();
        simpleAdapter.notifyDataSetChanged();
    }
}

}

2个回答

给list重新赋值,然后simpleAdapter.notifyDataSetChanged();

重新赋值simpleAdapter

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!