Binja
Binja

Reputation: 121

how to insert list.xml file inside main.xml

Someone help me to do like below!. I want to insert some list list.xml file bottom of the main.xml file. How to implement it?

   ----------------------------
    |    main.java              |
    |    main.xml               |
    |                           |
    |                           |
    |                           |
    |                           |
    |      ______               |
    |     |button|              |
    |                           |
    |                           |
    |                           |
    | _________________________ | 
    | |      list.java        | |
    | |      list.xml         | |
    | |                       | |
    | |                       | |
    | |                       | |
    | |                       | |
    | |                       | |
    |_|_______________________|_| 

I called list.java by using intent on the main.java .I also include list.xml to main.xml. When I press button list.xml should pop up like above figure. But list.xml comes up new window. How to solve this problem?

Upvotes: 3

Views: 482

Answers (3)

prakash
prakash

Reputation: 654

Yoy can try like this...

my sample code...

<RelativeLayout
    android:id="@+id/xK1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:orientation="vertical"
    >

    <include
        android:id="@+id/your id"// your id
        layout="@layout/list" >// add the list.xml here
    </include>
</RelativeLayout>

add in to your Main.xml.

Upvotes: 2

Paresh Mayani
Paresh Mayani

Reputation: 128438

As you want to re-use layout i.e. include existing layout inside another layouts, i would suggest you to go through this article: Re-using Layouts with <include/>.

Now as you want to include list.xml inside main.xml, write <include/> inside main.xml as below:

 <include layout="@layout/list"/>

Upvotes: 1

Sumedh Tambat
Sumedh Tambat

Reputation: 811

Try following code and make some changes as per your requirement. It's just guideline code. Use layout inflator service for that.suppose you have 2 files main and list then

public class Test extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    LinearLayout layoutMain = new LinearLayout(this);
    layoutMain.setOrientation(LinearLayout.HORIZONTAL);
    setContentView(layoutMain);
    LayoutInflater inflate = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    RelativeLayout layoutLeft = (RelativeLayout) inflate.inflate(R.layout.main, null);
    RelativeLayout layoutRight = (RelativeLayout) inflate.inflate(R.layout.list, null);

    RelativeLayout.LayoutParams relParam = new RelativeLayout.LayoutParams(
    RelativeLayout.LayoutParams.WRAP_CONTENT,
    RelativeLayout.LayoutParams.WRAP_CONTENT);
    layoutMain.addView(layoutLeft, 100, 100);
    layoutMain.addView(layoutRight, relParam);
}
}

Upvotes: 2

Related Questions