Markable ListView with changing Actionbar Actions - java

Im trying to find out how I can mark things in ListViews with a longClick. After I selected one item ,the Actionbar should change with diffrent options (buttons like delete, add , copy etc) which Im able to execute.I really didnt know how I can find these examples because Its a kind unique I guess. I founded threads where I can Mark an Item which gets a diffrent color and nothing else. How can I achieve this ?
Before selecting :
After long click :

Well you can add an onLongClickListener in your ListView or RecyclerView but for each list_item you will have to specify a checkbox that will become visible only when you longClick the ListView.
Then if you do not want to mess up the actionBar with new menu items you can create a context menu that will do your job.
You can use a ListPopupWindow or you can also use a CardView with a contexual menu as shown in the picture here.

Related

ListView inside ListView item

I want to ask one question, should I use ListView inside ListView item? Or I should redesign and remake my idea?
Example of ListView, but should be with couple sub items:
A ListView inside a ListView item is never a good idea. If you want sublists inside your list you can, for example, use a ExpandableListView. However, with the migration from ListViews to RecyclerViews I would recommend you go and implement this instead.
A ListView will never work correctly embedded as an item in another ListView. In fact, scrolling things inside other scrolling things is almost never what you really want to do, as it would be confusing to the user how to actually navigate your screen.

Restart/Load another Fragment | Android

I tried implement tab view in my app. This is the code that I used
http://developer.android.com/training/implementing-navigation/lateral.html
I created my fragment and I can go change between them. In the main activity I have menu the default menu (three points up right corner).
My question is how can I make that when I click on button in the menu one tab will be update/refresh/become another framgent, The name and the fragment. (I override onOptionsItemSelected..)
Thanks
If it help for someone. The solution is to use FragmentStatePagerAdapter and not FragmentPagerAdapter.
and manipulate the getItem function.
If I understand you correctly you want to use a menu item to switch to a specific tab, right?
To change to a tab grammatically you can use setSelectedNavigationItem like this:
ActionBar actionBar = getActionBar();
actionBar.setSelectedNavigationItem(0);
//this will put the screen to the first tab (tab at index 0).
If you want to do this with a menu item just put it in onMenuItemSelected.
Let me know if you need me to explain in more detail.
=================EDIT=====================
ah i think i understand, so replace the current tab fragment with another one in its place?
I think you can do that by:
actionBar.removeTabAt(position); //position is the current tab position.
actionBar.addTab(tab, position); //insert a new tab at that position
if its not selected after you insert it, try this:
actionBar.addTab(tab, position, setSelected)
i did not test this, so let me know if it does not work.

Highlight particular item on alert dialog in android

I am showing a list of items in an alert dialog. I'd like to make some items selected by default(highlight a row) - display nth item - when the dialog is shown.
I am a newbie to android and currently i am planning to extend arrayadapter to override getview method to highlight a particular row. But the problem is i am not sure whether my approach is right.
You probably dont need to override the adapter in this case. What you are suggesting will work, however it's cleaner if you have a background selector set for your list then you can mark the items in question as checked and have the selector highlight them. There are some good tutorials on ListViews in the android docs

Clicking on a ListView

I have a ListView with a header and a footer. I added two items with a class of my own extending the ArrayAdapter class. In this extended class, I have overridden the getView function because I want Views which are not TextViews to appear in my ListView.
On this ListView, I have set an onClickListener.
The problem is that this onClickListener is started when I click either on the header or on the footer, but never when I click on my items.
Of course, the View returned by getView is set to be clickable.
What am I missing?
Do you want to do something different when each list element is clicked? If so, you should programmatically set an onClickListener for each of those 2 elements added. Can you post your code?
It sounds like you are making this much more complicated than necessary. You can create your own layout for each row of a ListView using an XML file. This allows you to use any combinations of Views that you wish. To control what happens when the user clicks on a row in the ListView, your activity class should extend ListActivity and override onItemClickListener(). Alternatively, you can call setOnItemClickListener() on your ListView. For more details, I suggest that you read the Android ListView Developer Guide.
The solution I found : the click listener attached to the 'ListView' is only used for the clicks on the header and the footer. For my custom rows, in my ArrayAdapter's 'getView' function, I attached one listener to the 'TextView' and another to the 'ImageButton'.

Android ListView - onListItemClick does not work properly

I created a ListView in Android, and a corresponding ListActivity. Each individual item in the ListView has just one TextView (I plan to add an image and a CheckBox later).The ListActivity overrides the onListItemClick to perform certain tasks on click of any item on the list.
Heres whats happening -
When I first tried clicking on any item, nothing happened.
I then tried setting the properties "Focusable" and "Focusable in Touch Mode" to false for the TextView, as mentioned here, here and here. The List items started recognizing clicks, but only when I clicked somewhere away from the TextView. Whenever I tried clicking on the TextView or anywhere near it, it did not work.
I also tried changing various attributes like Clickable, but nothing has worked so far.
Any idea what I could be doing wrong ?
Thanks
After playing around with virtually every attribute in my TextView, I finally found the reason why it was not working. It was because of the attribute android:inputType="text" in my TextView. I'm not sure why I added that piece of code (I probably copied the TextView from one of my other applications), but removing it solves my problem.
Class which will listen clicks on ListView should implement interface AdapterView.OnItemClickListener

Categories