How can i stop executing getview() method in android? - android

I have two list view for displaying data from sqlite database.I displayed data without any problem.in second list view i have header with four columns.When i click on first list view , that related data displayed in second list it displayed based on position.By default i displayed first list view of the zero position related data in second list. the problem is , while scrolling the first list view it automatically calls the zero position values but i need the data of whatever position i clicked on first list view.I displayed data like below.How i can do?
Please can any on help?
first list view:
first........
second........
third........
I displayed data based on selection of first list view.
Second list view:
header
id Name Contact
1 ram 12345
Thanking in Advance.

easy bruteforce way is to use flag like this..
public boolean flag=false; // declare this as class variable outside both listview adapter class
then in 1st list view getview() function
if(!flag){
//display 2nd list view contents on 0th position of 1st list
flag=true;
}
in onItemClick() of 1st list view
//display 2nd list view contens based on position

Related

updating adapter by data from ListView (not the opposite)

I have a long ListView, which its items are editable (simple strings).
The user can change the content as he/she wants.
My problem is, that when I want to retrieve the new data from the List view,
I can not reach the invisible items in the list.
How can I retrieve the data from these items without scrolling to these items?
Is there a way to fill the adapter ,with the new data the user entered to the list?
I think you can do that. if you have reference of Adapter for that list view
you can call getCount and then iterate and while calling getItem(pos) , to get data for all the positions in the list view.

Access to data that is shown by a list view in android

I have a list view in an android program. Each row of this list view has a button. When user clicks one of these buttons, an action must be performed on data that is shown by that row.
How can I get access to that data and manipulate it?
Call getItem() on your Adapter to retrieve whatever the data is that is at that position within the Adapter. So, for example, if your Adapter is an ArrayAdapter<Restaurant>, getItem() will return the Restaurant for a given position.

List view postion comes to top after append data

I have a list view that fetch data from server when it scroll to bottom. once the data received it pass to the adapter via an array list.
But when i set the array list values to adapter, it appends the data and automatically the position moves to top.
Could some one tell me what is the problem occured here?
I guess that you recreated new Adapter and set it to your listview.
If you do like that, your listview will scroll to top.
To keep your listview item position, just call mAdapter.notifyDataSetChanged(); after update your array list.
Hope it can help you!

get text from specific position in listview android

I have a ListView with custom_row , every row has a textView1 and a textView2 , the list has now 2 records , and i have a button that is not on the list.
When i click the button i want to get the text from textView2 of the 2 records.
Is it possible?
I would take a shortcut, you ListView is being populated by an Adapter that uses a dataset. This dataset can be almost any datastructure such as Array, ArrayList, etc.
The layout you define, such as custom_row in you case only defines the structure of your view i.e. "where" items will show within on item on the list.
On the other hand, it is still your responsibility to tell the ListView "what" to show within the textView1 and textView2. You do this using the Adapter which connects the ListView to the dataset. More often than not, the ListView is a one-to-one mapping of the dataset i.e. the first item on the list is the first item in you dataset (I don't know what you are using for only two items, might be an array).
The ListView calls getCount() on the Adapter to find out how many total views there will be. It then call getView() for each view to be shown on the screen. It is in this method that you define what will actually show in a single view on the list (your custom_row).
Now you would know which entry of the dataset is supposed to populate which view in the ListView so you can just read it off there. For example, if your getView() does:
textView2.setText(getItem(position).getSomeTextField());
And the original dataset is an ArrayList named listDataSet
You could just do listDataSet.get(2).getSomeTextField()
NOTE: You will have to manage the scope of the dataset so that it's visible from wherever you are calling.
Get back your ListView (maybe already stored in an object thanks to findViewById, or by calling getListView() on your ListActivity).
Then call getItemAtPosition() on your list view, with the position you want.

Android : load next objects in ArrayAdapter by clicking on Item "load next Objects"

I have an ArrayAdapter<Cars> which shows my Cars in a List. That is good, but i want it to load other Cars dynamically by clicking on the last item in the list.
The last item should not be a Cars element it should only be a item which contains a TextView with text, for example "Load Next Items". Example: I have 13 Cars then the list would look like: Car/Car/Car/"Load Next Item".
When I click on that last item the next 3 Cars would be shown AND the "Load Next Item" and so on.
I am assuming you are not actually using ListView here.
you can bind an onclick listener function to Load next item.
That function will get the current set_of_cars_displayed (initially 0) and get set of cars as set_of_cars_displayed * 3 to (set_of_cars_displayed +1) * 3. This should be basic idea, you can post difficulty you are facing in implementation if any...
I'm not sure if you can do this with just an ArrayAdapter since everything has to be the same type.
What I would do is create my own class that extends BaseAdapter.
That class would have your array of cars and based in the getView method you can check the position and if it's the last one that your currently wanting to display you'll be able to inflate a different for the "click next" and assign and an click listener that will update your Array of cars . So you'll probably have to add a +1 to your getcount method for this last item. Don't forget to call notifydatasetchanged() to redraw your new elements.

Categories

Resources