Struggling to get my List View working properly - java

Before I start. I do apologise for not uploading any code. But I know already understand the problem I have. I just don't know how to sort it.
The problem I'm having is that I have a List View, which is populated by many rows. Each row has a Contacts name, how many contacts the user has in common. A contact display picture and an action button.
When the user clicks on the action button. They are promoted with a Popup Box. Displaying a further four more options; unfriend, block, message, and cancel.
When the user clicks on the unfriend or block button. The row that is associated with that button is then removed from the List View. Sounds simple right?
The List View also has a search filter, which the user may use. The can search by Contact names. Whilst the user is inserting values, the list view is refreshed consecutively, displaying Contacts that contain the values inserted into the search function. Same rules apply, the user may remove, block... Etc.
The problem I face is, when the user tries to unfriend a user by searching their contact name first. It tries to remove a Contact at position 0. Now as we may know, this searched contact may actually be at position 7 in the Array List. And thus, causes a problem. It removes the wrong user. Now, if the user doesn't use the search function. It actually works, the correct position is removed from the list. And ole Joe is happy.
I clear the ArrayList first before reading contacts that contain entered search values.
I'm sorry that I can't upload code, but my Mac isn't available at this time, and thus I can't access my project SC.
Could anybody give me some kind of indication on where I could have possibly went wrong?
Thanks, Peter.

First set the tag in getView method if you have adapter
textView.setTag(position) // set the tag (assuming you have textView in row, or you can set the tag for any other control)
Then while removing
int position = (Integer)v.getTag(); // get the tag that you had set before.
your_arraylist.remove(position); // remove
// your remaining code
notifyDataSetChanged();
Hope this gives you some idea. Happy coding.

Related

How to create a list with data tables as items that can be sorted

What I want to create
I want to create a list where each item in that list is an data table like below: The user needs te be able to sort items in the data table and needs to be able to sort the data tables itself.
Each table is going to represent a client and each item in that table is an order. The user will then collect the orders, if he collected an order the order wil dissapear but the user is also able to bring them back.
What I tried
I tried to put a Recyclerview inside a Recyclerview but this caused unitended side effects and bugs, also I read online that it is basically a bad practice. My initial intention was to use a recylcerview with a sortedlist.
I did some searching online and a lot of people recommended using categories between items so that you only need one list. But because I have data tables (CardViews) that can be independent sorted this isn't an option.
If anyone want to give me a nudge in the right direction, I would be really thankful.
What you can do you can use recycler view and in custom row check box with 8 text views and when position is 0 inflate categories like fat, calcium etc and after that position populate data and if you want next button which shows next items in list use fragments or pagination that should do the trick and you can achieve this using single recycler view. You can also use header to show categories.

How to remove one graph line from a graph and not all of them

So I have a method that graphs data from an arraylist, which contains names and there ranking for different decades. Every time the user types in a different name and pushes the "Graph" button on the GUI, the name will be graphed according to it's ranking for each decade. However, when I want to go clear the graph I want to be able to clear one graph line(each graph line is just one name's info) at a time when I push "Clear One" button. I have a clear all method, which looks likes this,
public void clearAll()
{
//Adds code to clear all names from the graphArray
graphArray.clear();
//Calls repaint() to update the graph
repaint();
}
and this belongs to my "Clear All" button. This works to clear all the different graph lines at the same time, but how can I clear just one at a time, specifically I want to remove the first graph line they entered first. So if the user enters 4 names(like sam, bill, bob, john), I want my clear one button to remove the oldest named entered which would be sam. Then the next time the button is hit, it would remove bill. So is there something like the
.clear()
that can do this or what do I need to do?
As your data is stored in an ArrayList called graphArray, you can call graphArray.remove(0) to delete the first element in that list, assuming that the first element is the oldest value.
This can easily be found using the API for ArrayList found here: https://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html

Refreshing/Updating contents of a JTable from Database, after user interaction

I have been researching this for days and have tried everything I have come across, but to no avail. I have built an item checkout system in JAVA using a Derby Embedded Database and everything that I have wanted it to do works great. The only thing I can't get to work is having my table update or refresh the information displayed after the user (A) Adds a new entry in the system due to a customer checking out an item. (B) A customer returns an item and is checked back into the system. (C) The table data is changed/fixed due to a previous user error. Case in point: The user checks out an item using the check out dialogue box, then clicks the check in dialogue box but the new entry just made, does not appear. Closing out of the program and going back into it then shows the new information.
I have a method called loadTable() that makes the DB connection all the way through building the table how I want and returns the table.
So far I have tried:
- Calling the loadTable() on any event (Button pressed, window closed, etc).
setFireTableDataChanged() method.
table.setModel(), here I tried inserting the loadTable().getModel or using a temp table.
jtable.tableChanged(new TableModelEvent(jtable.getModel())).
SwingUtilities.updateComponentTreeUI(yourJScrollPane); Ultimately it gets added to JSP.
table.UpdateUI();.
((DefaultTableModel)table.getModel()).fireTableDataChanged();.
repaint().
revalidate().
So far everything I have tried, does not produce the desired results.
I know you all will want to see code, there's a lot so I don't know what I should start with. This is my first time posting so, have mercy on me if i'm going about this the wrong way. Many thanks in advance!

Show an option list after click on EditText

I've one seen on an application for iPhone an interesting idea which consists of showing a list of options when we click on an area for text edition. For example, imagine I have a field called "City" (EditText) which I am suposed to enter the name of the city. When clicking on the EditText, a list automatically shows up with a few city suggestions (e.g. defined by the programmer) which can be selected. If the user doesn't like the suggestions, he writes the city himself and this city can be saved for this list for future.
I want to programme this on my App for android. I need that, when clicking on the EditText for introducing the data, a list automatically shows up with some suggestions defined by me (Programmer). However, I don't know how this can be done. I've googled but maybe it's hard to find the correct keywords to find a similar topic.
The idea is that the user should use the names already written in the list in 90% of the time and just write himself the new ones when it's necessary. Something like a dropdown list but with possibility of writing new stuff instantly without specific option.
How can this be achieved?
You Need Something Like View in android Named as
AutoTextComplete
Examples How to use this :
help
Best of luck
You can consider focus changed listener for Edittext,
when focus is gained you can show a context menu to choose data from.

Java PropertyResolutionException when binding netbeans combobox selected item

I have a JComboBox which I designed in the Netbeans GUI designer. I have successfully bound the "elements" of the box to an ArrayList<String> so that the box populates properly. However, it currently automatically displays the first element of the list as the selectedItem.
I tried to bind the selectedItem to an int at first, thinking it would just show the item at the indicated index. No go. I got a ginormous exception that I didn't understand.
Then, I noticed that in the "Binding" window, it said the element had to be an Object. So, I bound it to a String, thinking that it would find the element that matched that string and show that element. No dice. Now I'm getting some sort of "PropertyResolutionException". I've even tried to use an Integer object with the same result.
Any ideas would be appreciated.
Absent your sscce, it's hard to say where things have gone awry. For reference, setSelectedItem() works as advertised in this example that selects L&F by name.

Categories

Resources