Hello with regard to the known issue of unwanted checkboxes being checked while scrolling through a listview, can anyone please give me an idea how to use a checkedTextView properly so that i can maintain check state properly when scrolling through the list. I thought the listview takes care of maintaining the checkbox state when using a checkedtextView but that does not seem to be the case. or do i have to use the default Id for the checkedTextView. I can't seem to find an example that uses a cursorAdapter or a SimpleCursorAdapter for this case. Thank you
i have tried using this, but am not really sure what to do with the set tag position. here is a small piece of code:
//bindView() method in SimpleCursorAdapter
//viewHolder holder;
//Cursor c;
holder.checkedText = (CheckedTextView)view.findViewById(R.id.view_checked);
holder.checkedText.setTag(c.getPosition());
holder.checkedText.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
v.getTag();
((CheckedTextView) v).toggle();
}
});
my xml standard layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:choiceMode="multipleChoice"/>
<TextView android:id="#android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/no_notes"/>
</LinearLayout>
my custom layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:padding="6dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/viewNameText"
android:id="#+id/viewNameId">
</TextView>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:padding="2dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="start Date"
android:layout_gravity="right"
android:id="#+id/DateId">
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="start Time"
android:layout_gravity="right"
android:id="#+id/TimeId">
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
>
<CheckedTextView
android:id="#+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:checked="false"
android:focusable="false"
android:clickable="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
/>
</LinearLayout>
</LinearLayout>
I thought the listview takes care of maintaining the checkbox state when using a checkedtextView but that does not seem to be the case.
It should, if your ListView is android:choiceMode="multiple".
do i have to use the default Id for the checkedTextView
You might. The only times I have implemented a multiple choice ListView, I have used the standard row layout rather than a custom one.
Related
I'm using a ListView with an array adapter to display multiple list items. I'd like to have multiple TextView in the list item as per the picture
I'm currently using a linear layout which doesn't seem to be suitable... Would a relative layout help me achieve this?
Example code or tutorial link would be cool
Cheers
ListView xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/listViewTest"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
ArrayAdapter xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="89dp"
android:layout_marginLeft="4px"
android:layout_marginRight="10px"
android:layout_marginTop="4px"
android:layout_weight="0.34"
android:src="#drawable/ic_launcher" >
</ImageView>
<TextView
android:id="#+id/label"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_weight="0.97"
android:gravity="center"
android:text="#+id/label"
android:textSize="30dp" >
</TextView>
</LinearLayout>
I'm trying to add another textView under the existing textView using graphical layout tab in eclipse but my noobieness is getting in the way
This link uses Multiple Texts in a Single Listview...
http://publicstaticdroidmain.com/2011/12/building-a-custom-multi-line-listview-in-android/
Use the Code as follow..
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:text="Custom ListView Example" />
<ListView
android:id="#+id/srListView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
and,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingBottom="10dip"
android:paddingLeft="10dip"
android:paddingTop="10dip" >
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#C20000"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="#+id/cityState"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Follow the Link. It will Help you..
android Multiple selection ListView & Textview
And
http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/
Main.xml for List action
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="785dp"
android:choiceMode="multipleChoice" >
</ListView>
</LinearLayout>
And Row.xml as,..
<?xml version="1.0" encoding="utf-8"?>
<TableRow>
<TextView
android:id="#+id/StudNo"
android:layout_width="50px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5px" />
</TableRow>
<TableRow>
<TextView
android:id="#+id/StudNo"
android:layout_width="50px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5px" />
</TableRow>
</TableLayout>
and try with Customized Codes..
The linked picture has only two TextViews one below another. In case your using only 2 TextViews then a vertical LinearLayout should solve the purpose. However, if you intent to use more than two Views inside your ListItem then I would recommend you to use Relative Layout as it is way more flexible in holding multiple child-views, when it comes to aligning them with respect to one another.
You can follow a very simple tutorial provided by Google here:
Relative Layout
Make xml layout for list item which contains two textview
**listItem.xml**
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:gravity="center"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/textview1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
android:gravity="center"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textview2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
android:gravity="center"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
///*now in set this layout in your listview using Adapter as following*/
mlistview.setAdapter(new ArrayAdapter<String>(this,
R.layout.spinneritem, StringArray) {
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = null;
if (v == null) {
if (DiscountActivity.this != null) {
LayoutInflater vi = (LayoutInflater) DiscountActivity.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.listItem, null);
}
}
TextView txtview1 = (TextView) v.findViewById(R.id.textview1);
TextView txtview2 = (TextView) v.findViewById(R.id.textview2);
txtview1.setText("textview1");
txtview2.setText("textview2");
v.setTag(campaign);
return v;
}
});
I have a listview with each item containing an image, a textview and a checkbox. I am trying to have it so wherever you click within the item it highlights the checkbox. As stated in this response I set the focusable attribute of the checkbox to false, but I am still only able to click the checkbox to change its state. What's even more interesting is when I click on a checkbox every proceeding 10th item is also highlighted. Any suggestions?
Here is my xml for an item.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/image"
android:layout_width="50dip"
android:layout_height="50dip"
android:src="#drawable/stub"
android:scaleType="centerCrop"/>
<TextView
android:id="#+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="left|center_vertical"
android:textSize="20dip"
android:layout_marginLeft="10dip"/>
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"/>
</LinearLayout>
Main xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Clear Cache"/>
</LinearLayout>
create a CheckableLinearLayout or CheckableRelativeLayout for your ListView's item layout container,
set your listview's mode to 'multipleChoice'
find more details in the links below:
http://tokudu.com/2010/android-checkable-linear-layout/
http://www.marvinlabs.com/2010/10/custom-listview-ability-check-items/
in the process of populating the list, you can set a OnItemClickListener and change the checkbox to checked. try something like this:
list.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
ListItem item = (ListItem) adapter.getItem(position);
if(item.checkbox.isChecked())
item.checkbox.setChecked(false);
else
item.checkbox.setChecked(true);
}
});
in the main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" android:layout_marginTop="5dp">
<RelativeLayout
android:layout_width="450dp"
android:layout_height="25dp"
android:layout_marginLeft="7dp"
android:layout_marginTop="3dp">
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="450dp"
android:layout_height="25dp"
android:layout_marginLeft="7dp"
android:layout_marginTop="3dp">
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Clear Cache"/>
</RelativeLayout>
</LinearLayout>
Hope this help you...
I am new to this community as well as to android development.
For my study I need to make a (yes/no)questionnaire divided into 3 groups, some of the questions are quite long, so I want to make a part of it as big text and other part below as a small one.
I from tutorial on dev.and.com and made a TabLayout and for the moment I also have a LinearLayout for my questions
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/text_large"
android:textSize="16sp">
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/text_small"
android:textSize="12sp">
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2dp"
android:gravity="right">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/checkBxc">
</CheckBox>
</LinearLayout>
</LinearLayout>
Same is going to be for all of groups.
Code for tabLayout is like here
And AgroupActivity just displays a line of text right now (for testing purposes).
How can I make my layout to look like a list in each tab I have? Or maybe there are some other possibilities? As I understood, a simple ListView can't have anything(checkboxes in my case) in its tag?
You could use ListView to display a layout look like a list in each tabs.
With each tab content you use a ListView for each tab:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
And custom row (your_custom_row.xml) for each rows in ListView:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableRow
android:gravity="left"
>
<TextView
android:id="#+id/row_textview1"
android:textSize="25sp"
android:textStyle="bold"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:lines="1"/>
<TextView
android:id="#+id/row_textview2"
android:textSize="16sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:paddingRight="10dp"
android:lines="1"/>
</TableRow>
</TableLayout>
and use Adapter to bind data to your ListView.
I have dynamically generated ListView, which consists radio-buttons as list items.
Is it possible to use radiogroup functionality in that listview or for these radiobuttons.
I mean, I'd like, that if the user select a radio button the radio button selected before would deselected.
That is my solution at the moment, which I don't like very much. I just save selected radio button and if another one will be selected, deselect the saved one.
Thank you for your suggestions or links.
Here is my layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/bg_tile"
android:padding="10dp">
<TextView
android:id="#+id/text_station_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="TEST"
android:textColor="#color/black"
android:background="#color/transparent_white"/>
<ListView
android:id="#+id/list_lines"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
item.xml:
<?xml version="1.0" encoding="utf-8"?>
<RadioButton xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rb_lineId"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:paddingLeft="50dp"
android:background="#drawable/selector_custombutton"/>
But I also tried with this one:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/bg_tile"
android:padding="10dp">
<TextView
android:id="#+id/text_station_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="TEST"
android:textColor="#color/black"
android:background="#color/transparent_white"/>
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ListView
android:id="#+id/list_lines"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</RadioGroup>
</LinearLayout>
I think you want android:choiceMode="singleChoice". It's a bit tricky to implement (I don't know the exact specifics myself), but it's a starting point.
Currently I have a class that is extending the ListActivity class. I need to be able to add a few static buttons above the list that are always visible. I've attempted to grab the ListView using getListView() from within the class. Then I used addHeaderView(View) to add a small layout to the top of the screen.
Header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="#+id/testButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Income"
android:textSize="15dip"
android:layout_weight="1" />
</LinearLayout>
Before I set the adapter I do:
ListView lv = getListView();
lv.addHeaderView(findViewById(R.layout.header));
This results in nothing happening to the ListView except for it being populated from my database. No buttons appear above it.
Another approach I tried as adding padding to the top of the ListView. When I did this it successfully moved down, however, if I added any above it, it pushed the ListView over. No matter what I do it seems as though I cannot put a few buttons above the ListView when I used the ListActivity.
synic, I tried your suggestion previously. I tried it again just for the sake of sanity, and the button did not display. Below is the layout file for the activity and the code I've implemented in the oncreate().
//My listactivity I am trying to add the header to
public class AuditActivity extends ListActivity {
Budget budget;
#Override
public void onCreate(Bundle savedInstanceState) {
Cursor test;
super.onCreate(savedInstanceState);
setContentView(R.layout.audit);
ListView lv = getListView();
LayoutInflater infalter = getLayoutInflater();
ViewGroup header = (ViewGroup) infalter.inflate(R.layout.header, lv, false);
lv.addHeaderView(header);
budget = new Budget(this);
/*
try {
test = budget.getTransactions();
showEvents(test);
} finally {
}
*/
// switchTabSpecial();
}
Layout.xml for activity:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<ListView android:id="#android:id/list" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView android:id="#android:id/empty" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="#string/empty" />
</LinearLayout>
findViewById() only works to find subviews of the object View. It will not work on a layout id.
You'll have to use layout inflater to convert the xml to it's corresponding View components. Something like this:
ListView lv = getListView();
LayoutInflater inflater = getLayoutInflater();
View header = inflater.inflate(R.layout.header, lv, false);
lv.addHeaderView(header, null, false);
I'm not sure why your code wasn't just throwing an error. findViewById() was probably just returning null, and so no header was added to your list.
Here is the simpliest sollution:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/background">
<include layout="#layout/actionbar"/>
<ListView
android:id="#+id/tasklist_TaskListView"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:textColor="#color/baseFont"/>
<include layout="#layout/bottombar"/>
</LinearLayout>
or
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/background">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<ListView
android:id="#+id/tasklist_TaskListView"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:textColor="#color/baseFont"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
instead of button you can add another horizontal linear layout
After some research I was able to figure out that mixing TableLayout and LinearLayout within my ListActivity XML document I was able to add a header to the document. Below is my XML document if anyone is interested to see it. While synic's approach is probably the right approach after work with his solution for sometime I was unable to make it function the way I wanted it.
AuditTab.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.audittab);
getListView().setEmptyView(findViewById(R.id.empty));
}
audittab.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
android:layout_width="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent">
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_weight="1">
<Button
android:id="#+id/btnFromDate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:layout_weight="1" />
<Button
android:id="#+id/btnToDate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:layout_toRightOf="#+id/btnFromDate"
android:layout_weight="1" />
<Button
android:id="#+id/btnQuery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Query"
android:layout_toRightOf="#+id/btnToDate"
android:layout_weight="1" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="#android:id/list"
android:layout_width="300dip"
android:layout_height="330dip"
android:scrollbars="none" />
<TextView
android:id="#+id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10dip"
android:text="- Please select a date range and press query." />
</LinearLayout>
</TableRow>
</TableLayout>
AuditItem.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:padding="10sp">
<TextView
android:id="#+id/transactionDateLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date: " />
<TextView
android:id="#+id/transactionDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/transactionDateLabel" />
<TextView
android:id="#+id/transactionTypeLabel"
android:layout_below="#id/transactionDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Type: " />
<TextView
android:id="#+id/transactionType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_below="#id/transactionDate"
android:layout_toRightOf="#id/transactionTypeLabel" />
<TextView
android:id="#+id/transactionAmountLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:text="Amount: "
android:layout_below="#id/transactionDate"
android:layout_toRightOf="#id/transactionType" />
<TextView
android:id="#+id/transactionAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/transactionDate"
android:layout_toRightOf="#id/transactionAmountLabel" />
<TextView
android:id="#+id/transactionCategoryLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Category: "
android:layout_below="#id/transactionAmountLabel" />
<TextView
android:id="#+id/transactionCategory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/transactionAmountLabel"
android:layout_toRightOf="#id/transactionCategoryLabel"
/>
<TextView
android:id="#+id/transactionToAccountLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="To Account: "
android:layout_below="#id/transactionCategoryLabel" />
<TextView
android:id="#+id/transactionToAccount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/transactionCategoryLabel"
android:layout_toRightOf="#id/transactionToAccountLabel" />
<TextView
android:id="#+id/transactionFromAccountLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="From Account: "
android:layout_below="#id/transactionToAccountLabel" />
<TextView
android:id="#+id/transactionFromAccount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/transactionToAccountLabel"
android:layout_toRightOf="#id/transactionFromAccountLabel" />
<TextView
android:id="#+id/transactionNoteLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Note: "
android:layout_below="#id/transactionFromAccountLabel" />
<TextView
android:id="#+id/transactionNote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/transactionFromAccountLabel"
android:layout_toRightOf="#id/transactionNoteLabel" />
<Button
android:id="#+id/editTransactionBtn"
android:layout_width="wrap_content"
android:layout_height="40sp"
android:visibility="gone"
android:text="Edit"
android:layout_below="#id/transactionNoteLabel"/>
<Button
android:id="#+id/deleteTransactionBtn"
android:layout_width="wrap_content"
android:layout_height="40sp"
android:text="Delete"
android:layout_below="#+id/transactionNoteLabel"
android:visibility="gone"
android:layout_toRightOf="#+id/editTransactionBtn"
android:ellipsize="end"/>
</RelativeLayout>
The ListView answer above is useful but scrolls with the list and doesn't keep the header graphics at the top. The best solution I've found is to set a custom title to the activity. Here is what my constructor looks like:
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.your_listview_layout);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.your_header);
...
Where your_listview_layout.xml configures a ListView, and your_header.xml contains whatever custom header layout that you like. Just note that the three lines above must be called in exactly that order to not cause run-time problems.
The tutorial that helped me was http://www.londatiga.net/it/how-to-create-custom-window-title-in-android/ and you can find many related pages on Stack Overflow by searching for the term "setFeatureInt"
Adding a static header is easy, just make a separate relative view that has the alignParentTop (or bottom, right or left) attribute set to true.