I have Created a ListView and set a background image.Everything goes fine except I am unable to click on the right side of the row of ListView.Can anybody help me this.
Below is the xml file...
<ListView
android:layout_width="wrap_content"
android:id="#+id/JSONListView"
android:layout_height="wrap_content"
android:background="#drawable/listbg"
android:focusable="false"
android:cacheColorHint="#00000000"
android:visibility="visible" >
</ListView>
And I am not using any View.
Use the attribute
android:layout_width="match_parent"
and set click listener for items.
I guess you have created your custom adapter. If so, just go to the getView() method of that custom adapter and on the holder instance of that portion of listitem add a onCLickListener.
Provide more info. XML layout, etc.
Im guessing there is a view there or it is not filling the entire width but difficult to say.
Android ListView Activity
Related
i have two view
<VideoView
android:id="#+id/player"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/lighter_gray"
android:id="#+id/imageView"
/>
I want to select only one view to shown at run time , is there container for them to do the job ?
i searched and found something like viewswitcher ,but i dont want to switch between them i only want to display one of them
You can set video view and image view visibility to gone in xml by adding android:visibility="gone"
and setVisibility to visible in java code based on the requirement or which view you want to show.
If you have hundreds of items in list.
You can simply managed by list adapter with one own type field and create custom adapter with the list and switch the views on each position as per your requirement.
I'm fairly new to Android and when I have a ListView containing only a single item that item appears at the bottom of the ListView. I'm assuming this is because the ListView is populated from the bottom. So, is there a way to get the ListView to populate from the top? Or are there any other methods to get the same result? Thank you.
Here is my definition of the ListView
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/fileList"
android:layout_centerHorizontal="true"
android:layout_above="#+id/previous"/>
When I remove android:layout_above="#+id/previous the problem is fixed, but my list extends behind the button I have at the bottom off the screen.
Check the android:gravity attribute in your defined ListView in static XML. It sounds like you may have it set to android:gravity="bottom"
I was able to solve this problem by setting android:layout_height and android:layout_width to fill_parent
remove this line, list will show from top.
android:layout_above="#+id/previous"
I'm trying to make ListView in a widget where there are multiple clickable items in each row. For example, if each row has data containing a link, one button in the row to open the link and another to share the link.
Sample code:
Widget layout
<LinearLayout...>
<TextView../>
<ListView with id="list_view" />
</LinearLayout>
Each list row in the ListView has:
<LinearLayout with id="listRowParent">
<TextView../>
<Button with id="openBtn"/>
<Button with id="shareBtn"/>
</LinearLayout>
I'm able to set onClick of each row using
remoteViews.setPendingIntentTemplate(R.id.list_view,
*<PendingIntent>*); //in onUpdate
and remoteView.setOnClickFillInIntent(R.id.openBtn, *fillIntent*); // in adapter
which works fine, but I can't have setPendingIntentTemplate for a list row button by doing remoteViews.setPendingIntentTemplate(R.id.shareBtn,
);
since nothing happens on clicking the button if I do this.
Question:
Is what I'm attempting possible? If yes, help is greatly appreciated :)
My bad. I should be using
remoteViews.setPendingIntentTemplate(R.id.list_view,
*<PendingIntent>*);
for both the buttons, but I was trying to use the button's ID directly in the second. Got fixed.
I am writing an app that has a ListView of text. In each row there is a combination of text and links. I added an OnItemLongClickListener to the list and made the links clickable with
my_text.setMovementMethod(LinkMovementMethod.getInstance());
The problem is, if I am able to click the link, I cannot get the textView to register the LongClick.
I have tried different methods to make the links clickable such as
android:autoLink="web
But this doesn't make the links clickable.
My question is: Is there a different way that I should set the LongClickListener, or a different way to make the links clickable?
Has anyone else encountered a similar problem?
I should note that right now the OnItemLongClickListener makes the links register the LongClicks but this causes a problem when a textview doesnt have a link or a user tries to longClick somewhere else in the view (besides the link)
Code:
I programatically inflate a relativeLayout containing a list view and add it to a view flipper:
RelativeLayout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ListView
android:id="#+id/my_list"
style="#style/listViewSimple"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#f9f9f9"
android:cacheColorHint="#00000000"
android:divider="#ccc"
android:dividerHeight="1px"
android:fadingEdge="none"
android:fadingEdgeLength="30dp"
android:footerDividersEnabled="false"
android:headerDividersEnabled="false"
android:persistentDrawingCache="none" >
</ListView>
</RelativeLayout>
Adding everything programatically:
RelativeLayout list = (RelativeLayout) LayoutInflater.from(MyActivity.this).inflate(R.layout.my_list_layout, null);
vf.addView(list);
ListView lv = (ListView) list.findViewById(R.id.my_list);
lv.setOnItemLongClickListener(listLongListener);
Making Links clickable(in getView() of adapte):
my_tv.setText(Html.fromHtml(formatted_text)));
my_tv.setLinkTextColor(linkColor);
my_tv.setMovementMethod(LinkMovementMethod.getInstance());
This makes links clickable but seems consume all clicks before they get to the textview. I tried to add a longClickListener that returns false but that didn't seem to have any affect.
My temporary fix is to set a itemLongClickListener and an onItemClickListener to the listItem and just display a dialog with the clickable text in onListItemClick. This works but adds an extra click for users to interact with the text
I would create a custom Adapter, set your ListView to use that Adapter, and then in getView, set a View.OnClickListener on the TextView that has your text and a View.OnLongClickListener on the TextView that has your link. Remove the existing listeners you referred in your question so that they don't conflict.
My temporary fix is to set a onItemLongClickListener and an onItemClickListener to the listItem and just display a dialog with the clickable text in onItemClick. This works but adds an extra click for users to interact with the text.
If a better answer is posted I will change selected answer
I need to show a list of items, the items are read from a database, and it is possible there is no item, in this case, I just want to show a TextView saying "there is no item", I think I could implement this by using relative layout, both list and text are in center of parent, they are displayed alternatively, but is there any way better than this?
Thanks!
Adding to Aleadam , Bill Mote
You may call at any time AdapterView.setEmptyView(View v) on an AdapterView object to attach a view you would like to use as the empty view.
The snippet is as follows:
empty = (TextView)findViewById(R.id.empty1);
list = (ListView)findViewById(R.id.list1);
list.setEmptyView(empty);
Make sure you keep the ListView and TextView inside the same parent.
For detailed description please refer this
If you're using a ListActivity, that is the default behavior. If not, then you can set the ListView visibility to GONE and a TextView visibility to VISIBLE.
Aleadam is right. Here's an example XML in support of his answer:
<?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/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<TextView
android:id="#id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#drawable/red"
android:gravity="center_vertical|center_horizontal"
android:textStyle="bold"
android:text="#string/error_no_groups"
/>
</LinearLayout>
The first tutorial on the Android developer website explains how to do this:
http://developer.android.com/resources/tutorials/notepad/notepad-ex1.html
(Look under Step 4)
Snippet:
The ListView and TextView can be thought as two alternative views, only one of which will be displayed at once. ListView will be used when there are notes to be shown, while the TextView (which has a default value of "No Notes Yet!" defined as a string resource in res/values/strings.xml) will be displayed if there aren't any notes to display.
The View with the empty id is used automatically when the ListAdapter has no data for the ListView. The ListAdapter knows to look for this name by default. Alternatively, you could change the default empty view by using setEmptyView(View) on the ListView.