How to open PopUp Window
when EditText
is long pressed where user can type or paste content and than can press ok which then place the entered text in the EditText
and i don't want user to use enter key.
My main motive is that user can see whole text at once as EditText
size is small in my apk.
Note:- I'm beginner in android programming and this is my first question. :)
What I understood with your Question. My answer is
attaching the code for your reference
Popup window xml -
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="250dp"
android:layout_height="250dp"
android:background="#FFFFE0"
android:orientation="vertical"
android:paddingLeft="7dip"
android:paddingTop="7dip"
android:paddingRight="7dip"
android:paddingBottom="7dip">
<EditText
android:id="@+id/edit_pop"
android:layout_width="match_parent"
android:layout_height="120dp"
android:ems="10"/>
<Button
android:id="@+id/btok"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="OK" />
</LinearLayout>
Main activity -
public class MainActivity extends Activity implements OnLongClickListener
{
EditText vedt=null,edPop;
Button btOk=null;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
vedt = (EditText) findViewById(R.id.editText1);
vedt.setOnLongClickListener(this);
}
@Override
public boolean onLongClick(View v)
{
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupWindow popupWindow = new PopupWindow(popupView,android.view.ViewGroup.LayoutParams.WRAP_CONTENT,android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
edPop = (EditText)popupView.findViewById(R.id.edit_pop);
btOk = (Button)popupView.findViewById(R.id.btok);
edPop.requestFocus();
edPop.setText(vedt.getText().toString());
popupWindow.showAtLocation(popupView, Gravity.CENTER,5,5);
popupWindow.setOutsideTouchable(false);
popupWindow.setFocusable(true);
popupWindow.update();
btOk.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
vedt.setText(edPop.getText().toString());
popupWindow.dismiss();
}
});
return false;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With