I am developing meme create application and generating text view Programmatically. If i generate 2 text views programmatically always i can get text of last generated text view. I can't get text of previous generated text view. How can I get text of which I on click text view .
// Create TextView programmatically.
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);
}
});
TextVieweach time this will override the last one .