0

从活动开始

Intent intent = new Intent(StartActivity.this, MarkersActivity.class);
startActivityForResult(intent, GoMarkerReturn);  

调用其他有 CustomListAdapter 的活动扩展 BaseAdapter。listview有一张图片,点击后关闭当前activity并将结果返回给启动activity

public class CustomListAdapter extends BaseAdapter {
...
    public View getView(int position, View convertView, ViewGroup parent) {
        holder.imggo.setOnClickListener(new View.OnClickListener() {
            ...
            @Override
            public void onClick(View v) {
            int clickedPosition = (Integer)v.getTag();
            NewsItem newsItem = (NewsItem)listData.get(clickedPosition);                
            Long goID = newsItem.getID();

            Intent myIntent = new Intent(v.getContext(), StartActivity.class);
            myIntent.putExtra("goID", goID);
            setResult(0, myIntent);

setResult(0, myIntent) 不起作用!

4

2 回答 2

1

StartActivityForResultsetResult用于在活动之间传递值。在您的情况下,您需要在第二个活动中调用 finish() 以便第二个活动被销毁并且第一个活动进入前台。

这是一个很好的教程来了解它是如何工作的。数据传输

于 2013-09-18T00:09:38.767 回答
0
public class CustomListAdapter extends BaseAdapter {
...
    public View getView(int position, View convertView, ViewGroup parent) {
    ...
        holder.imggo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent myIntent = new Intent(v.getContext(), StartActivity.class);
                myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                myIntent.putExtra("goID", goID);
                v.getContext().startActivity(myIntent);

public class StartActivity extends Activity{
...
    @Override
    protected void onResume() {
        Intent intent = getIntent();
        Long goID = intent.getLongExtra("goID", 0);
        if (goID > 0){
               ...
于 2013-09-18T22:47:25.363 回答