我有一个具有自定义视图的活动.
我必须添加活动结果:
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...>
}
}
Run Code Online (Sandbox Code Playgroud)
查看课程:
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;
}
Run Code Online (Sandbox Code Playgroud)
finishFunction - 我必须在这里写一下完成ActView与父活动的结果?
我需要这样的事情:
Intent intent = new Intent();
intent.putExtra(dataname, value);
setResult(RESULT_OK,intent);
finish();
Run Code Online (Sandbox Code Playgroud)
因为Context
您正在使用的是Activitys context, you can cast the view
Activity的上下文,并在其上调用finish().
例如:
private void finishFunction() {
Activity activity = (Activity)getContext();
activity.finish();
}
Run Code Online (Sandbox Code Playgroud)
从设计角度来看,它可能不是最好的选择
归档时间: |
|
查看次数: |
3172 次 |
最近记录: |