我有一个活动有自己的看法。
我必须添加活动结果:

    public class ActView extends Activity implements OnClickListener {
<...code...>
@Override
    protected void onCreate(Bundle savedInstanceState) {
    <...code...>
     layout = (LinearLayout) findViewById(R.id.chart_container);
        timelineview = new VDrawTimeLine(this,contentFull);
        timelineview.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        timelineview.setBackgroundColor(0xffffffff);
        timelineview.setVisibility(View.VISIBLE);

        layout.addView(timelineview);

    <...code...>
    }
}

视图类:
public class VDrawTimeLine extends View implements OnTouchListener{
<...code...>
public VDrawTimeLine(Context context, ArrayList<_MainData> contentFull) {
        super(context);
        this.con = context;
        this.content = contentFull;
        <...code...>
    }
}
@Override
    public boolean onTouch(View v, MotionEvent event) {
        // TODO Auto-generated method stub
        finishFunction();//I need here finish event this activity result for ActView Activity.
        return true;
    }

finishFunction-我必须在这里写些什么才能用父活动的结果完成actview?
我需要这样的东西:
Intent intent = new Intent();
    intent.putExtra(dataname, value);
    setResult(RESULT_OK,intent);
    finish();

最佳答案

因为您使用的Context是活动的Activitys context, you can cast the view上下文,并对其调用finish()。
例如:

private void finishFunction() {
   Activity activity = (Activity)getContext();
   activity.finish();
}

也许从设计的角度来看这不是最好的选择

10-07 19:07