is there any way to get the entire row layout (container and childs of the row layout) from an xml
What you are looking for is how to inflate
a view (LayoutInflator)
Now that you have the right term, it should be easy to find examples, inflate
is popular in ListView
tutorials. For an example, take a look at at getView()
in this tutorial for an example:
HowTo: ListView, Adapter, getView and different list items’ layouts in one ListView
http://android.amberfog.com/?p=296
mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
...
convertView = mInflater.inflate(R.layout.item1, null);
... edit some of the properties (like the TextViews of the row layout) ...
Once you inflate the view, you can search for the widgets within it, so you can manipulate it.
holder.textView = (TextView) convertView.findViewById(R.id.text);
If your view is fairly complex and/or you will often be looking for widgets within it, I want to point out the ViewHolder technique, shown in the example referenced, relevant 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 a LinearLayout?
Presumably, you're already programatically adding to the LinearLayout
, but if you want to see some code, here's an example that shows setting 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);
...
Lastly, you can do alot (including custom rows) with the AdapterView
/ Adapter
paradigm, e.g. using ListView
with a SimpleCursorAdapter
. It may save you some code by looking into it. Some babbling about it here:
Android ListView with different layouts for each row