is there any way to get the whole row layout (container and row layout children) from xml
What you are looking for is an inflate view ( LayoutInflator )
Now that you have the right term, it's easy to find examples; inflate popular in ListView tutorials. For example, take a look at getView() in this guide for an example:
HowTo: ListView, Adapter, getView, and various list items in a single ListView
http://android.amberfog.com/?p=296
mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); ... convertView = mInflater.inflate(R.layout.item1, null);
... edit some properties (e.g. TextViews of the line layout) ...
Once you inflate a view, you can search for widgets in it so that you can manipulate it.
holder.textView = (TextView) convertView.findViewById (R.id.text);
If your look is rather complicated and / or you often look for widgets inside it, I want to specify the ViewHolder technique shown in the example below, the corresponding bits below:
// Data structure to save lookups public static class ViewHolder { public TextView textView; } ... // Save lookups to widgets for this view in ViewHolder in tag ViewHolder holder = new ViewHolder(); holder.textView = (TextView) convertView.findViewById(R.id.text); view.setTag(holder); ... // Grab saved widgets - no need to search tree for them via lookup again ViewHolder holder = (ViewHolder) convertView.getTag(); holder.textView.setText(mData.get(position));
... and add the result to LinearLayout?
Presumably, you are already programmatically adding to LinearLayout , but if you want to see some code, here is an example that shows the setting of some layout parameters:
Android LinearLayout
http://developerlife.com/tutorials/?p=312
// main "enclosing" linearlayout container - mainPanel final LinearLayout mainPanel = new LinearLayout(ctx); { mainPanel.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); mainPanel.setOrientation(LinearLayout.VERTICAL); ... } ... // top panel LinearLayout topPanel = new LinearLayout(ctx); { // WEIGHT = 1f, GRAVITY = center topPanel.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1)); ... } ... // bottom panel LinearLayout bottomPanel = new LinearLayout(ctx); { LayoutUtils.Layout.WidthFill_HeightWrap.applyLinearLayoutParams(bottomPanel); ... } ... // add the panels mainPanel.addView(topPanel); mainPanel.addView(bottomPanel); ...
Finally, you can do a lot (including custom strings) using the AdapterView / Adapter paradigm, for example. using a ListView with a SimpleCursorAdapter . It can save you some code by learning it. Some chat about it here:
Android ListView with different layouts for each row