public class ZpopView extends Dialog {
public Context context;
public ZpopView(Context context) {
super(context);
this.context = context;
}
public ZpopView(Context context, int themeResId) {
super(context, themeResId);
this.context = context;
}
protected ZpopView(Context context, boolean cancelable, DialogInterface.OnCancelListener cancelListener) {
super(context, cancelable, cancelListener);
this.context = context;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View view = View.inflate(context, R.layout.itempop, null);
setContentView(view);
Button paizhao = view.findViewById(R.id.paizhao);
Button xiangce = view.findViewById(R.id.xiangce);
Button quxiao = view.findViewById(R.id.quxiao);
paizhao.setOnClickListener(new onClickPop());
xiangce.setOnClickListener(new onClickPop());
quxiao.setOnClickListener(new onClickPop());
}
public class onClickPop implements View.OnClickListener {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.paizhao:
httpClick.onhttpclick1();
break;
case R.id.xiangce:
httpClick.onhttpclick2();
break;
case R.id.quxiao:
httpClick.onhttpclick3();
break;
}
}
}
private HttpClick httpClick;
public void setHttpClick(HttpClick httpClick) {
this.httpClick = httpClick;
}
public interface HttpClick {
void onhttpclick1();
void onhttpclick2();
void onhttpclick3();
}
}
public class TwoActivity extends AppCompatActivity {
private ImageView name;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_two);
name = findViewById(R.id.name);
name.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ZpopView zpopView = new ZpopView(TwoActivity.this);
zpopView.show();
zpopView.setHttpClick(new ZpopView.HttpClick() {
@Override
public void onhttpclick1() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.addCategory("android.intent.category.DEFAULT");
startActivityForResult(intent, 0);
}
@Override
public void onhttpclick2() {
}
@Override
public void onhttpclick3() {
}
});
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case 0:
Bitmap data1 = data.getParcelableExtra("data");
name.setImageBitmap(data1);
break;
}
}
}