我在活动 A 的 gridview 中有视图。在活动 B 中,如果发生某些操作,我想在 gridview 的视图上添加小复选标记。当我回到活动 A 时,我想在同一个网格视图中显示这个带有这个小复选标记的视图。我将如何做到这一点?
这是我的包含网格视图的活动
public class LogoSelectionActivity extends Activity {
static int pos;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_logos);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
pos = position;
if(ImageAdapter.items[position] == 0){
Intent intent = new Intent(LogoSelectionActivity.this, LogoActivity.class);
intent.putExtra ("clicked_position", position);
startActivity(intent);
}else{
Intent intent = new Intent(LogoSelectionActivity.this, CorrectActivity.class);
startActivity(intent);
}
}
});
}
这是我比较输入的其他活动:
public class LogoActivity extends Activity{
EditText text;
Button check;
Boolean a;
int id;
Names name;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_logo);
check = (Button) findViewById(R.id.Check_button);
text = (EditText) findViewById(R.id.editText1);
ImageView view = (ImageView)findViewById(R.id.imageView1);
final ImageView incorrect = (ImageView)findViewById(R.id.incorrect);
switch (getIntent().getIntExtra ("clicked_position", -1))
{
case 0:
view.setImageResource(R.drawable.adese);
id = R.drawable.adese;
break;
case 1:
view.setImageResource(R.drawable.birvar);
id = R.drawable.birvar;
break;
case 2:
view.setImageResource(R.drawable.agaoglu);
break;
case 3:
view.setImageResource(R.drawable.akinsoft);
break;
default:
view.setImageResource(R.drawable.afra);
id = R.drawable.afra;
}
name = Names.forDrawable(id);
check.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
a=name.isCorrect(text.getText().toString());
if(a==true){
ImageAdapter.items[LogoSelectionActivity.pos] = 1;
Intent intent = new Intent(LogoActivity.this, CorrectActivity.class);
startActivity(intent);
}
else{
incorrect.setVisibility(0);
}
}
});
}
}
如果 a 返回 true,当用户返回第一个活动时,我想在网格视图中的视图上放一个小复选标记。