开发者

Scrollable EditText on custom dialog in android

I need to put EditText box with vertical scrollbar on custom dialog.i.e when I entered more than one line on edittext, it should be scrolled. Here I used android: scrollable="vertical" on xml. It works fine. When I use two edittext boxes, the curor will move to second edittext box when I press enter on first. Any mistakes?

My code...

EditText edit1,edit,edit0;
Button ok;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.main);

    final Dialog dialog = new Dialog(summaact.this);
      dialog.setContentView(R.layout.main);
      edit0=(EditText)dialog.findViewById(R.id.edit0);
      edit=(EditText)dialog.findViewById(R.id.edit);
      edit1=(EditText)dialog.findViewById(R.id.edit1);

      edit0.setInputType(InputType.TYPE_NULL);
      edit.setInputType(InputType.TYPE_NULL);
      edit1.setInputType(InputType.TYPE_NULL);

      ok=(Button)dialog.findViewById(R.id.o开发者_C百科k);
        dialog.setTitle("Content Management page");
        dialog.setCancelable(true);
        ok.setOnClickListener(new OnClickListener(){

             public void onClick(View v){
                 String str0=edit0.getText().toString(); 
                String str=edit1.getText().toString(); 
                String str1=edit.getText().toString(); 

                Toast.makeText(summaact.this,str0,Toast.LENGTH_SHORT).show();
                Toast.makeText(summaact.this,str,Toast.LENGTH_SHORT).show();
                Toast.makeText(summaact.this,str1,Toast.LENGTH_SHORT).show();


                dialog.dismiss();
             }
         });

         dialog.show();

    }

My xml...

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
     <EditText
    android:id="@+id/edit0"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 

 />
    <EditText
    android:id="@+id/edit"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 

 />

<EditText
    android:id="@+id/edit1"
    android:layout_width="fill_parent" 
    android:layout_height="100px" 
    android:scrollbars="vertical"


 />

 <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/ok"
    android:text="OK"/> 

</LinearLayout>


new answer:

Try using:

android:inputType="textMultiLine"

in EditText

edit:

I made an example and it works with textMultiline:

@Override
protected void onResume() {
    super.onResume();

    AlertDialog.Builder b = new AlertDialog.Builder(this);
    View view = LayoutInflater.from(this).inflate(R.layout.main, null);
    b.setView(view);
    b.setTitle("Content Management page");

    b.create().show();
}

Layout is the same except one EditText:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
    android:id="@+id/edit0"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
<EditText
    android:id="@+id/edit"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
<EditText
    android:id="@+id/edit1"
    android:layout_width="fill_parent"
    android:gravity="top|left"
    android:layout_height="100dp"
    android:scrollbars="vertical"
    android:inputType="textMultiLine" />
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/ok"
    android:text="OK" />

</LinearLayout>

Scrollable EditText on custom dialog in android

Where did you have problem?


try

YourEditText.setMovementMethod(new ScrollingMovementMethod());

and be sure to set scrollbars true

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜