Textview`s LinkMovementMethod blocks listitem touch event - android

I have some problem with Listview. Listview has list items that consist of imageview and textview. Textview contains clickable links. When I set LinkMovementMethod to textviews, listitems doesn`t receive onclick event. I still cannot find any right solution=(. Can anyone explane how to solve it or give an example of using textview with clickable links inside listitem? Thanks.
Here is textview creation in adapter:
TextView text = (TextView) ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
.inflate(R.layout.post_content_text, null);
SpannableString sString = new SpannableString(d.getText());
//I have my own class UrlSpan that contain fields startPosition, endPosition and urlLink
for (UrlSpan us : ((TextData) d).getUrls())
{
URLSpan urlSpan = new URLSpan(us.getUrl());
sString.setSpan(urlSpan, us.getStart(), us.getEnd(), SpannableString.SPAN_INCLUSIVE_INCLUSIVE);
}
text.setText(sString);
text.setMovementMethod(LinkMovementMethod.getInstance());
view.addView(text);
and list item is:
<?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:visibility="visible" >
<LinearLayout
style="?PostListRow"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="10dp"
android:orientation="vertical"
android:padding="10dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="65dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/user_image"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_margin="3dp"
android:clickable="true"
android:src="#drawable/ic_no_photo" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="55dp"
android:layout_margin="0dp"
android:orientation="vertical" >
<TextView
android:id="#+id/user_title"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:clickable="true"
android:textSize="#dimen/title_in_list" />
<TextView
android:id="#+id/post_datetime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:textSize="#dimen/text_size_small" />
</LinearLayout>
<TextView
android:id="#+id/post_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="123" />
</LinearLayout>
<!-- it is a view where textview with links is to be added to -->
<LinearLayout
android:id="#+id/post_data"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="6" >
</LinearLayout>
<TextView
android:id="#+id/post_view"
style="?PostText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:visibility="gone" />
<LinearLayout
android:id="#+id/topic_edit_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
</LinearLayout>
</LinearLayout>

try to add this attribute
android:descendantFocusability="beforeDescendants"
to your listview
from the documentation:
it defines the relationship between the ViewGroup and its descendants when looking for a View to take focus. it seems to me that when you have some active views like buttons or edittext and etc in your listview you have to define descendantFocusability

Related

Add TextView programmatically but text color become gray like disabled

Why does my textview automatically change the color to gray as if they were disabled when I add them programmatically? I am sure I did not set any color to gray in my layout.
Here's my code for adding textview programmatically:
LayoutInflater inflater = (LayoutInflater) getActivity().getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View chat = inflater.inflate(R.layout.chat_list_item, null);
((TextView)chat.findViewById(R.id.chat_name)).setText(obj.getString("username"));
LinearLayout container = (LinearLayout) getActivity().findViewById(R.id.chat_list);
container.addView(chat);
here is my layout item:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="10"
android:orientation="horizontal"
android:id="#+id/chat_view"
android:clickable="true"
>
<ImageView
android:layout_width="0dp"
android:layout_height="80dp"
android:layout_weight="2"
android:id="#+id/chat_propic"
android:scaleType="fitCenter"
android:src="#drawable/face"
/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="8"
android:paddingLeft="10dp"
android:weightSum="3"
android:orientation="vertical"
>
<!-- name and last message-->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="10"
android:orientation="horizontal"
>
<TextView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="7"
android:gravity="bottom"
android:id="#+id/chat_name"
android:text="UserNAMEEEE"
android:textStyle="bold"
/>
<TextView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="3"
android:gravity="bottom"
android:id="#+id/chat_time"
android:text="30/05/2015"
/>
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:gravity="center|left"
android:id="#+id/chat_message"
android:text="asjkdgaksgkdagskdakjsdhklahskld"
/>
<View
android:layout_height="1dp"
android:layout_width="fill_parent"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="#ff828282"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
You can add a line after creating the TextView
chat.setTextAppearance(context, android.R.style.TextAppearance_DeviceDefault);
Might not work but I remember my friend having a problem similar to this and I told him this: "activate" the textView.
chat.setActivated(TRUE);
The "TRUE" might be wrong, there might be something like View.ACTIVATED or so ,test it out yourself please :)
Let me know if you need anything else and if it worked.

Textview Link Movement Method blocks listitem

I have some problem with Listview. Listview has list items that consist of imageview and textview. Textview contains clickable links. When I set LinkMovementMethod to textviews, listitems doesn`t receive onclick event. I still cannot find any right solution=(. Can anyone explane how to solve it or give an example of using textview with clickable links inside listitem? Thanks.
i tried to many ways but i couldnt do useful thins ! tank you for help . Here is textview creation in adapter:
TextView text = (TextView) ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
.inflate(R.layout.post_content_text, null);
SpannableString sString = new SpannableString(d.getText());
//I have my own class UrlSpan that contain fields startPosition, endPosition and urlLink
for (UrlSpan us : ((TextData) d).getUrls())
{
URLSpan urlSpan = new URLSpan(us.getUrl());
sString.setSpan(urlSpan, us.getStart(), us.getEnd(), SpannableString.SPAN_INCLUSIVE_INCLUSIVE);
}
text.setText(sString);
text.setMovementMethod(LinkMovementMethod.getInstance());
view.addView(text);
and list item is:
<?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:visibility="visible" >
<LinearLayout
style="?PostListRow"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="10dp"
android:orientation="vertical"
android:padding="10dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="65dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/user_image"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_margin="3dp"
android:clickable="true"
android:src="#drawable/ic_no_photo" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="55dp"
android:layout_margin="0dp"
android:orientation="vertical" >
<TextView
android:id="#+id/user_title"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:clickable="true"
android:textSize="#dimen/title_in_list" />
<TextView
android:id="#+id/post_datetime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:textSize="#dimen/text_size_small" />
</LinearLayout>
<TextView
android:id="#+id/post_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="123" />
</LinearLayout>
<!-- it is a view where textview with links is to be added to -->
<LinearLayout
android:id="#+id/post_data"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="6" >
</LinearLayout>
<TextView
android:id="#+id/post_view"
style="?PostText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:visibility="gone" />
<LinearLayout
android:id="#+id/topic_edit_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
</LinearLayout>
</LinearLayout>

Multiple TextViews in the same List Item

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;
}
});

Top view in a LinearLayout embedded in a ScrollView only half visible

In my app, I insert pairs of spinners into a linearlayout, which is inside a scrollview. Problem is, when I add enough spinners, the top two are partially obscured. Here's what I'm talking about.
<LinearLayout
android:id="#+id/ChordHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#android:drawable/bottom_bar"
android:orientation="horizontal" >
<Button
android:id="#+id/addChordButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="Add Chord" />
<TextView
android:id="#+id/spacetext1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=" "
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/removeChordButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="Remove Chord" />
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
android:id="#+id/ChordList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:isScrollContainer="true"
android:orientation="vertical"
android:weightSum="100" >
(Spinners get inserted here)
</LinearLayout>
</ScrollView>
</LinearLayout>
And here is the code that inserts spinners into the list, if the problem is with that.
Spinner chordName = new Spinner(this);
Spinner chordType = new Spinner(this);
LinearLayout container = new LinearLayout(this);
container.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout chordList = (LinearLayout) findViewById(R.id.ChordList);
chordName.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 80, 50));
chordName.setAdapter(nameAdapter);
container.addView(chordName); //add name spinner to container
chordType.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 80, 50));
chordType.setAdapter(typeAdapter);
container.addView(chordType); //add type spinner to container
container.setBackgroundResource(android.R.drawable.bottom_bar);
container.setPadding(10, 0, 10, 0);
chordList.addView(container); //add container to list layout
Here is my layout.. try it out :)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/ChordHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:drawable/bottom_bar">
<Button
android:id="#+id/addChordButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="Add Chord" />
<Button
android:id="#+id/removeChordButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:ellipsize="middle"
android:text="Remove Chord" />
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/ChordHeader"
>
<LinearLayout
android:id="#+id/ChordList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</RelativeLayout>
Now for the buttons you might want to set a dimen if you really want them the same size.
Here is how to store dimensions in Android : More Resource Types: Dimension
Try getting a reference to the top item in the list and then request focus on it, after you are done adding the spinners.
chordList.getChildAt(0).requestFocus();

Android: Adding static header to the top of a ListActivity

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.

Categories

Resources