ListView with buttons - android

I have a ListView with few elements, each item contains two buttons with a selector so when I'm pressing the buttons the image change.
My problem is when I tap on the some ListView element the buttons on this specific ListView also changing like I pressed the buttons.
Is this a known issue??
Thank's.
listview xml:
<ListView
android:id="#+id/ViewIndex"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="false"
android:choiceMode="none"
android:fadingEdge="none" >
</ListView>
ListView listView = (ListView) findViewById(R.id.ViewIndex);
listView.setOnItemClickListener(new OnItemClickListener(){
}
I have a custom adapter, that add xml which contain two buttons.

My best guess would be that you are using the onclicklistener of the listview instead of the onclikclisteners of each individual button. If this is the case you should set onclicklisteners for each button and do your actions there.

Related

Add header and footer to list view without setting adapter

I have a simple list view, and I want to add header and footer to this list view without setting an adapter for it.
How do I add a header and footer to a ListView without setting an adapter, if it is possible?
xml code for listView:
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/listView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"/>
and code for adding header and footer:
ListView listView = (ListView)findViewById(R.id.listView);
Button headerButton = new Button(getApplicationContext());
headerButton.setText("Header");
listView.addHeaderView(headerButton);
Button footerButton = new Button(getApplicationContext());
footerButton.setText("Footer");
listView.addFooterView(footerButton);
You won't be able to achieve that.
The way header and footer layouts work with ListView is the following: Whenever you add a header or footer to your ListView, it will cause your own adapter to be wrapped by a WrapperListAdapter and basically make your header and footer items be treated as list items in their own way(handled by the adapter of course). Thus, your ListView can't really know about these items if it has no adapter.

Android: How to make Grid view with clickable grid items and nested views (buttons,Image) by remote(For Android TV)

How to make Grid view with click able grid items and nested views (buttons,Image) by remote(For Android TV)
I just want to click able image and button in grid view item should add to play my list if I navigate on button by Remote navigation not by touch
Thank you!!!
How to navigate through d pad in grid view sub items if grid view item have two sub items image button and another button
It is no difference between touch screen or remote control for methods like onClickListener or etc.
For remote control, you need to focus on the element first, than you can click the element.
I have not use the gridView on TV before, but I have used the recyclerView and scrollView. I think they have same situation.
I've try the default simpleAdapter to create the gridView, and it's no problem with the nested views that I can focus and click each grid items after I set the onItemClickListener to the gridView.
I guest your problem is that the grid item conflicts with the button in the grid item.
To avoid this situation, you need to set android:descendantFocusability="blocksDescendants" for the container of your custom grid item view. It will block the items statement in that parent layout.
If you want the button change in the different statement, you can give the button this parameter: android:duplicateParentState="true".
That will let the button follow it's parent's statement.
By the way, don't forget to set some changes to different statement for the grid items (background changes or etc), or you will not know which grid item you have focused :P.
Hope this will help you :)
PS. The following is the sample code for the custom grid item layout. Maybe the example can help you to understand what I mentioned easily.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants" >
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:duplicateParentState="true"/>
</LinearLayout>
2015.01.06 23:11 update:
How to navigate through d pad in grid view sub items if grid view item
have two sub items image button and another button
For this case you should not use OnItemClickListener. Instead, you should make your grid item unfocusable and unclickable, and than set OnClickListener for both two buttons.
You can set the parameters in your customize adapter for the gridView. In getView method you can set each of the grid item view just like convertView.focusable(false) and convertView.clickable(false).
After that, you can set the click listener and give the method you want to do for the buttons in adapter.
Don't care about the D-pad action. Actually, D-pad will work automatically if there are elements can be focused.
The key point for this question is the conflict between grid item and its child elements. You could have just one part to be focused: grid item (the parent view), or the buttons (the child views).

LongClick textView, clickable link

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

Clicking on the entire row of Android ListView

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

Android: when list has ended than it should show button

Iamtrying to have a button at the bottom of the list, so when u scroll down and the list has ended than there will be a button "Get more", which will populate the list with more items.
But the button is not visible. this is how my xml file looks like.
Maybee this occurs because of the scroller,, maybe the scroller only works for the list.
<ListView
android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<Button android:id="#+id/search_browser"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Get more ads" />
</LinearLayout>
That's not really the correct way of doing it.
In your case, the button will ALWAYS be visible at the bottom of the list.
If you want it to be visible only when user scrolls at the bottom, use:
yourListView.addFooterView(someFooterView)
This footer view can (logically) be any view (button, layout), inflated, or created at runtime.
P.S. http://developer.android.com/reference/android/widget/ListView.html#addFooterView(android.view.View)
P.S.S. In your case, you need to remove your button declaration in XML, leaving only ListView.
And in code do
Button button = new Button(this);
button.setText("Get more ads");
((ListView) findViewById(R.id.list).addFooterView(button);
Try the following:
android:layout_height="0dip"
android:layout_weight="1"
instead of
android:layout_height="fill_parent"
for your ListView.
I believe however that is more appropriate to have an auto-growing list.

Categories

Resources