我正在开发模因创建应用程序和生成文本视图编程。如果我以编程方式生成2个文本视图,我总是可以获得最后生成的文本视图的文本。我无法获取以前生成的文本视图的文本。我怎么能得到我点击文本视图的文本。
//以编程方式创建TextView。
textView = new StickerTextView(MainActivity.this);
textView.setText(edt.getText().toString());
textView.setTextSize(1000);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (popupWindow !=null)
{
popupclose();
}
text = "";
text = textView.getText().toString();
popupwindow(v);
}
});
public void popupwindow(View v) {
FrameLayout fl = (FrameLayout) findViewById(R.id.canvasView);
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
popupView = layoutInflater.inflate(R.layout.my_action2,null);
popupWindow = new PopupWindow(popupView, RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
ImageButton btnClose = (ImageButton)popupView.findViewById(R.id.imageView_close);
btnClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//popupWindow.dismiss();
popupclose();
}
});
Button btntext = (Button)popupView.findViewById(R.id.btnone);
btntext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showEditDialog1();
}
});
public void showEditDialog1() {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this, R.style.MyDialogTheme);
LayoutInflater inflater = this.getLayoutInflater();
final View dialogView = inflater.inflate(R.layout.custom_dialog, null);
dialogBuilder.setView(dialogView);
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
edt1 = (EditText) dialogView.findViewById(R.id.edit1);
edt1.setText(text);
dialogBuilder.setTitle(Html.fromHtml("<font color='#FFFFFF'>EDIT TEXT </font>"));
//dialogBuilder.setMessage("Enter text below");
dialogBuilder.setPositiveButton(Html.fromHtml("<font color='#FFFFFF'>Done</font>"), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Create TextView programmatically.
textView.setText("");
textView.setText(edt1.getText().toString());
textView.setTextSize(1000);
textView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
return false;
}
});
textView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent me) {
if (me.getAction() == MotionEvent.ACTION_DOWN) {
status = START_DRAGGING;
final float x = me.getX();
final float y = me.getY();
lastXAxis = x;
lastYAxis = y;
v.setVisibility(View.INVISIBLE);
} else if (me.getAction() == MotionEvent.ACTION_UP) {
status = STOP_DRAGGING;
flag = 0;
v.setVisibility(View.VISIBLE);
} else if (me.getAction() == MotionEvent.ACTION_MOVE) {
if (status == START_DRAGGING) {
flag = 1;
v.setVisibility(View.VISIBLE);
final float x = me.getX();
final float y = me.getY();
final float dx = x - lastXAxis;
final float dy = y - lastYAxis;
xAxis += dx;
yAxis += dy;
v.setX((int) xAxis);
v.setY((int) yAxis);
v.invalidate();
}
}
return false;
}
});
// Add TextView to LinearLayout
if (canvas != null && textView == null) {
canvas.addView(textView);
}
hidekeypad(MainActivity.this);
}
});
1条答案
按热度按时间tp5buhyn1#
你应该从参数(view v)中获取值,该参数通过onClickLisenter接口的onClick覆盖函数传递。因为你使用
StickerTextView
,所以: