1

How can I create a TextView (with Java code, not xml) with layout_width=fill_parent ?

The TextView should be editable.

0

4 Answers 4

6

If i don't understand question wrongly,you need to create an EditText programatically.then,Try using:

EditText et=new EditText(context);
et.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

EDIT :

Import for LayoutParams:

import android.view.ViewGroup.LayoutParams;
Sign up to request clarification or add additional context in comments.

1 Comment

You understand it ok. what is the import for LayoutParams ?
4

Its not a TextBox, its EditText in Android.

Anyway, you can create it run time using:

EditText ed = new EditText(this);    // Create a new EditText

// Setting the type of input that you want
ed.setInputType(InputType.TYPE_CLASS_TEXT);       

// setting height/width for your editText
ed.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));  

Comments

0

EditText et = new EditText(context);// this gets you a new textbox

//assuming you're in eclipse when you hit the . after et you'll see all its various properties that you can set as you like.

then when you're ready you either set it as the setContentView(et);// here it's the only thing on the screen

or

add it to whatever layout you have already set.

Comments

0

Create layoutParams with appropriate width and height by

LayoutParams params = //choose appropriate constructor

//beware about right import .

now Create textBox and setLayoutParams

EditText t = new EditText(this);

t.setLayoutParams(params);

1 Comment

he's asking about EditText, not TextView

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.