-1

This is my Project XML Layout

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:id="@+id/flowLayout"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:orientation="vertical" >

    <!-- enter code here -->
</LinearLayout>

I need to access it in the JAVA file which should contain 3 sentences in 3 text views ...

public class MainActivity extends Activity {

private View layout;
@Override

    protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    findViewById();

        //enter code here
    }
    private void findViewById() {

    View layout = findViewById(R.id.flowLayout);

        //enter code here
    }
}
manlio
  • 18,345
  • 14
  • 76
  • 126
user2109950
  • 29
  • 1
  • 7
  • 1
    I can't understand, what is the problem? – Emil Adz Apr 04 '13 at 06:55
  • I need to give 3 sentences in 3 text view in JAVA file and not in XML .... using flow layout – user2109950 Apr 04 '13 at 07:00
  • how to give width and height of the text view in the corresponding JAVA file?? – user2109950 Apr 04 '13 at 07:22
  • you need to create a LayoutParams object, see updated answer. – Emil Adz Apr 04 '13 at 07:25
  • did you find my answer helpful? – Emil Adz Apr 04 '13 at 07:39
  • I want to add 3 text view in java file which is coming from 2 text view in very first line and 3rd text view is coming from next line coming to front line not from last. so i want to add orientation is horizontal in xml file. could u refer this follow link alsohttp://stackoverflow.com/questions/549451/line-breaking-widget-layout-for-android to see images in 38 question. – user2109950 Apr 04 '13 at 08:05
  • yes, i got it then its useful for my project. – user2109950 Apr 04 '13 at 08:08
  • Ya ... As per ur instructions i gave 3 sentences in 3 correspondin text views but the third sentence is getting disappeared due to the resoution of the mobile. I need to display it in the new line. How to do that?? For example it should be like in the image in this link.. http://stackoverflow.com/questions/549451/line-breaking-widget-layout-for-android – user2109950 Apr 04 '13 at 08:43
  • @Emil Adz : Answer Pls ..http://stackoverflow.com/questions/15806706/android-flow-layout-in-java – user2109950 Apr 04 '13 at 09:00

1 Answers1

0

To add a TextView to your layout do this:

LinearLayout layout = (LinearLayout)findViewById(R.id.flowLayout); //depending on which layout is it.

Then, Create a TextView, set it text and add it to the layout:

TextView tvText = new TextView(this);
tvText.setText("your desired sentence");
layout.addView(tvText);

and do this for all 3 of your TextViews, for setting the height and width use LayoutParams (example):

LinearLayout.LayoutParams layoutParams=new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(0, 0, 2, 0);

As you can see this is the way you set Mergins as well, in the end set those params to the textView:

tvText.setLayoutParams(layoutParams);
Emil Adz
  • 40,709
  • 36
  • 140
  • 187