Search Results

Search found 64 results on 3 pages for 'listadapter'.

Page 1/3 | 1 2 3  | Next Page >

  • Is there a super simple List / ListAdapter example out there for android

    - by slim
    I have a web service that returns a super simple list of objects MyObject[] data = webServiceCall(); MyObject has 1 field i want to display, "Name" (i.e. data[0].Name ) How can i turn this into an activity that lists just the name of these objects in a scrollable listActivity in android. I am getting really confused with Cursors and am not sure if I need Cursors and I"m not sure what kind of adapter to implement (baseAdapter, SimpleAdapter etc) So i guess i'm looking for three things, the activity , the adapter and the layout.xml Just trying to figure this android stuff out, definately a noob here

    Read the article

  • ListView/ListAdapter paging

    - by synic
    I'm trying to implement paging in a custom ListAdapter. Right now I'm just making the request for the next page when the last item in the ListView becomes visible, by checking in getView() if position is >= the size of ListAdapter.getCount(). It works fine, but I'm wondering if there's a better way (or a different way) that will only make the request once the last item in the list is actually visible to the user. Anyone know of a way?

    Read the article

  • Using a SimpleAdapter, how can i map images to a ListAdapter Row? using android sdk

    - by nathanjosiah
    Here is the code that i have for the adapter. ArrayList<HashMap<String, Object>> mylist = new ArrayList<HashMap<String, Object>>(); for (CustomClass imageObject : myArray) { HashMap<String, Object> map = new HashMap<String, Object>(); BmpFromURL myBmp = new BmpFromURL(image.getURL()); map.put("image", myBmp.getMyBitmap()); mylist.add(map); } SimpleAdapter adapter = new SimpleAdapter(this, mylist, R.layout.series_list_row, new String[]{"image"}, new int[]{R.id.ImageView01}); this.setListAdapter(adapter); getMyBitmap() returns a Bitmap.

    Read the article

  • How to refresh ListAdapter/ListView in android

    - by user2463990
    I have database with 2 table, custom layout for my listView, and I'm using ListAdapter to display all data on ListView - this works fine. But, I have problem when I wish display something other on listView from my Database. The data is just append on my ListView - I won't this! How I refresh/update ListAdapter? This is my MainActivity: ListAdapter adapter; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); search = (EditText) findViewById(R.id.search); lista = (ListView) findViewById(android.R.id.list); sqlite = new Sqlite(MainActivity.this); //When apps start, listView is populated with data adapter = new SimpleAdapter(this, sqlite.getAllData(), R.layout.lv_layout, new String[]{"ime","naziv","kolicina","adresa"}, new int[]R.id.kupac,R.id.proizvod,R.id.kolicina,R.id.adresa}); setListAdapter(adapter); search.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before,int count) { // TODO Auto-generated method stub String tekst = s.toString(); ArrayList<HashMap<String, String>> rez = Sqlite.getFilterData(tekst); adapter = new SimpleAdapter(MainActivity.this, rez,R.layout.lv_layout, new String[]{"ime","naziv","kolicina","adresa"}, new int[]{R.id.kupac,R.id.proizvod,R.id.kolicina,R.id.adresa}); lista.setAdapter(adapter); } } The problem is when the method onTextChanged is called. I get all the data but the data just append to my ListView. How to fix it? And this is my Sqlite class where is needed method: ArrayList<HashMap<String,String>> results_criteria = new ArrayList<HashMap<String,String>>(); public ArrayList<HashMap<String, String>> getFilterData(String criteria) { String ime_kupca = ""; String product = ""; String adress = ""; String kolicina = ""; SQLiteDatabase myDb = this.getReadableDatabase(); Cursor cursor = myDb.rawQuery("SELECT " + DB_COLUMN_IME + "," + DB_COLUMN_NAZIV + "," + DB_COLUMN_KOLICINA + "," + DB_COLUMN_ADRESA + " FROM " + DB_TABLE1_NAME + "," + DB_TABLE2_NAME + " WHERE kupac.ID = proizvod.ID AND " + DB_COLUMN_IME + " LIKE '%" + criteria + "%'", null); if(cursor != null){ if(cursor.moveToFirst()){ do{ HashMap<String,String>map = new HashMap<String,String>(); ime_kupca = cursor.getString(cursor.getColumnIndex(DB_COLUMN_IME)); product = cursor.getString(cursor.getColumnIndex(DB_COLUMN_NAZIV)); kolicina = cursor.getString(cursor.getColumnIndex(DB_COLUMN_KOLICINA)); adress = cursor.getString(cursor.getColumnIndex(DB_COLUMN_ADRESA)); map.put("ime", ime_kupca); map.put("naziv", product); map.put("kolicina", kolicina); map.put("adresa", adress); results_criteria.add(map); }while(cursor.moveToNext()); //cursor.close(); } cursor.close(); } Log.i("Rez", "" + results_criteria); return results_criteria;

    Read the article

  • Android: ListAdapter populating image (icon) source

    - by user117701
    I'm populating a list from the DB, and i have a image field in the DB which contains a URL to a image file. ListAdapter adapter=new SimpleCursorAdapter(this, R.layout.row, constantsCursor, new String[] {"title", "subtitle", "image"}, new int[] {R.id.value, R.id.title, R.id.icon}); However, the other fields are populated, but the image remains empty. Why?

    Read the article

  • Android ListAdapter Repaint

    - by xger86x
    Hi, i have the following problem. I fill a ListView with a custom ArrayAdapter with data from a BD. However, in background, i'm updating those datas from the info provided by an API, so the idea is when the update finish, the adapter shows the updated data instead its "old version". The problem is that when i do that, i notice a lag while the adapter is updating itself. Is the any efficient solution to avoid this? Thanks

    Read the article

  • ListAdapter to modify the datasource (which is an arraylist)

    - by dusker
    Hi Everyone, here's a problem that i've run into lately: I have a listview with a custom adapter class, the adapter takes in a listview and populates the listview with elements from it. Now, i'd like to have a button on each row of a listview to remove the item from it. How should i approach this problem? Is there a way to remotely trigger a method in the activity class and call notifydatachanged() method on the adapter to refresh the listview? thanks in advance for your help and some code snippets if possible best regards peter

    Read the article

  • Android: Registering ContextMenu for a Custom ListAdapter

    - by primal
    Hi, I made a custom list adapter extending the Base adapter. Each item in the list has an imagebutton, 2 textviews and a button. I tried to add the context menu to the list so as to display some options for an item in the list. registerForContextMenu(getListView()); I used a MenuInflater object to inflate the context menu xml file. But on clicking the items in the list nothing shows up or the usual highlighting of the item of list on click isn't shown. Is it that the context menu doesn't work for custom list views? Any help would be much appreciated. Regards, Primal

    Read the article

  • call setListAdapter() from inside a thread

    - by Mats Hofman
    Hi, I have a problem with my ListActivity, i use a thread to show a ProgressDialog where get a list of all installed applications. I turn it into a list adapter and than i want to set the listadapter of the activity but i can't do that from the thread. I get the following error: ERROR/AndroidRuntime(14429): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. new Thread() { public void run() { showList(); // the method where i get all the apps and have the setListAdapter(); method progressDialog.dismiss(); } }.start(); How do I get it so I can use the setListAdapter from inside my thread

    Read the article

  • android: ListView.setAdapter() is causing IllegalStateException. Not sure how to fix it.

    - by Stev0
    I'm trying to populate a listview with the contents of various ListAdapters based upon the results of a switch statement nested in an OnItemClickListener. When clicking the item, the application was force closing, so I ran it through the dev tools and android debugger. Eclipse is showing me the in the main thread that the application has suspended due an IllegalStateException. I have a marginal understanding of what the particular exception indicates, but not sure how to fix it, or what in my code is causing it to be thrown. Code as follows: final ListView lv = (ListView) findViewById(R.id.main_list); final String[] autos = getResources().getStringArray(R.array.auto_array); final ListAdapter la_auto = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_2, autos); And then further down in the portion dealing with the onclicklistener gallery.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView parent, View v, int position, long id) { switch(gallery.getSelectedItemPosition()) { case 0: lv.setAdapter(la_auto); break;

    Read the article

  • Android ListView with Checkbox: automatically unchecks

    - by Kilnr
    Hi, I've got a ListView with a custom BaseAdapter. The list items contain CheckBoxes that need to represent a property from a database. I use CheckBox.setOnCheckedChangeListener with a new OnCheckedChangeListener to detect changes, so I can change the database based on the current state of the CheckBox. Pretty straightforward stuff so far. However, when scrolling further down the list, previously checked CheckBoxes get unchecked. I suspect this happens as soon as the views are recycled (I'm using the convertView/ViewHolder technique). How can I stop this? What's going wrong? Thanks in advance. Edit: To make things a bit clearer, the problem is that recycling views somehow calls OnCheckedChangeListener#onCheckedChanged(buttonView, isChecked) with isChecked == false.

    Read the article

  • Android: ViewHolder pattern and different types of rows?

    - by tomash
    ViewHolder pattern improves ListView scrolling framerate, as seen in following example: http://developer.android.com/intl/de/resources/samples/ApiDemos/src/com/example/android/apis/view/List14.html Is it possible to keep this pattern while using different kind of Views for different rows? In other words, is it possible to do something like: public View getView(int position, View view, ViewGroup parent) { // calculate viewID here if (view == null || *view is not null but was created from different XML than viewID* ) { view = mInflater.inflate(viewId, null);

    Read the article

  • How can I manage the height of android spinner items?

    - by rushinge
    I have an android spinner that's populated by a list of strings using an ArrayAdapter and it operates fine, however because of the way the spinner is displayed I'm running into a display height problem with the list items. At first glance it would seem that the ArrayAdapter can use a single layout for displaying options which leads to the problem I'm having. When displaying the current item in the spinner (when the user is not selecting a new item from the list) the spinner pads the text so that the spinner is a reasonable size for clicking on. However when the user taps on it and brings up the list to select a new item, the list items presented are way to small height-wise. If I use an item layout that presents the list items at a reasonable height, then the spinner itself becomes exorbitantly huge due to it's own padding of the list item. Any ideas on how I can manage the height of these two item display modes so that effectively they display with the same height value instead of the spinner height being larger than the list item display height?

    Read the article

  • Android: ListActivity design - changing the content of the List Adapter

    - by Rob
    Hi, I would like to write a rather simple content application which displays a list of textual items (along with a small pic). I have a standard menu in which each menu item represents a different category of textual items (news, sports, leisure etc.). Pressing a menu item will display a list of textual items of this category. Now, having a separate ListActivity for each category seems like an overkill (or does it?..) Naturally, it makes much more sense to use one ListActivity and replace the data of its adapter when each category is loaded. My concern is when "back" is pressed. The adapter is loaded with items of the current category and now I need to display list of the previous category (and enable clicking on list items too...). Since I have only one activity - I thought of backup and load mechanism in onPause() and onResume() functions as well as making some distinction whether these function are invoked as a result of a "new" event (menu item selected) or by a "back" press. This seems very cumbersome for such a trivial usage... Am I missing something here? Thanks, Rob

    Read the article

  • How to call notifyDataSetChanged() from a generic Adapter

    - by Matty F
    An OnItemClickListener for a ListView has the following method: @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) I'd like to have the adapter behind the ListView refresh, and I believe this is done through the use of: BaseAdapter.notifyDataSetChanged() How do I use the parent parameter in the onItemClick method to do this? So far I've tried: parent.getAdapter().notifyDataSetChanged(); This throws an error because the object returned is of class HeaderViewListAdapter, which for reasons unknown isn't a subclass of BaseAdapter.

    Read the article

  • CheckBox won't toggle in Android ListView with focusable="false"

    - by user3563124
    I'm creating a ListView with a custom Adapter for displaying my entries. Each row contains a checkbox, and my adapter contains the following code: CheckBox cb = (CheckBox) v.findViewById(R.id.item_sold); cb.setChecked(p.isSold); setupCheckboxListener(cb, v, position); ... private void setupCheckboxListener(CheckBox check, final View v, final int position) { check.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { CheckBox cb = (CheckBox) v; if (cb.isChecked()) { System.out.println("Should become false!"); cb.setChecked(false); } else { System.out.println("Should become true!"); cb.setChecked(true); } } }); My row XML file includes the following: <CheckBox android:id="@+id/item_sold" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.10" android:layout_gravity="center" android:gravity="center" android:focusable="false" android:clickable="false"/> But anytime I press one of the checkboxes, check.isChecked() returns true, even if the box is unchecked. I even checked to make sure that the checkboxes were distinct and weren't picking up just the last value/etc. Setting up the listeners inline instead of in a method doesn't seem to help, either. It's literally just the isChecked() condition that isn't working appropriately - it seems to always give me the inverse value. Setting an onClick on the row is not acceptable in this case because I need to allow row selection for something else. What could be causing this issue?

    Read the article

  • ListAdapters and WrapperListAdapter algorithm

    - by Matty F
    This logic is written in a function with signature private void showDialog(final AdapterView<? extends Adapter> parent, String title, String message, final Tag subject) Is there a better way of doing this? // refresh adapter SimpleCursorAdapter adapter; if (parent.getAdapter() instanceof WrapperListAdapter) { adapter = (SimpleCursorAdapter) ((WrapperListAdapter) parent.getAdapter()).getWrappedAdapter(); } else { adapter = (SimpleCursorAdapter) parent.getAdapter(); } adapter.getCursor().requery(); adapter.notifyDataSetChanged(); Also, is there any point in having AdapterView<? extends Adapter> in the signature and not just AdapterView<?>?

    Read the article

  • Android: how to set click events on ListView?

    - by Capsud
    Hey there, I'm looking to be able to open up a new view or activity when I click on an item in my ListView. Currently I have a list of restaurants, and when i click on a particular restaurant I want it to open up another screen that will show its address, google map etc. What I need help with is knowing how to set click events on the items in the list. At the moment I dont have a database of the items, they're just Strings. Can someone help me with getting me to this stage? Thanks alot.

    Read the article

  • Android: duplicate items in ListVew. Maybe getView() called too many times?

    - by gonzobrains
    Hi, I am trying to create a simple program which displays a "shopping cart" list of items, along with a few buttons below it to manage the cart. The biggest problem is that items are getting duplicate entries in the list view. That is, for every item I want to enter I see it appear two times in the list view. What's the problem? Also, the scrollable area of my cart is not big enough. How do I set it so that it is bigger but I can still see my buttons? Perhaps I should put the buttons above the cart? Here is my shopping cart's layout XML: Here is the layout for individual row items: <LinearLayout android:orientation="vertical" android:layout_width="0dip" android:layout_weight="1" android:layout_height="fill_parent"> <TextView android:id="@+id/BookTitle" android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" android:singleLine="true" android:gravity="center_vertical" / <TextView android:id="@+id/BookPrice" android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" android:singleLine="true" android:ellipsize="marquee" / Thanks, gb

    Read the article

  • List view and list adapters for displaying json

    - by Rahul Varma
    Hi, I am trying to display the text from json in a list view. I got help for retrieving the json text from the following... http://www.josecgomez.com/2010/04/30/android-accessing-restfull-web-services-using-json/comment-page-1/#comment-498.... But my problem is that i cant figure out how to display them in list view. I also want to get only some of the text from url(for example, alerttext and date). Can anyone help me in declaring the list adapter and list view in order to display the data in the way i want... Plzzzz...

    Read the article

  • Where are graphically pleasing examples of Lists

    - by slim
    Anyone know of good code examples of how to make lists look different than your everyday average black list or more graphically pleasing than you usually see in android apps. I've looked through google code but haven't found too many. I'm looking for different and eye catching lists. I hope this question isn't too generic. Also i'm open to anything, code, examples, blog posts, etc, you name it. I've really struggled with lists and making them look more snazzy. I'm talking more the code level not the graphics or icons used.

    Read the article

  • Android: Adding header to dynamic listView

    - by cg5572
    I'm still pretty new to android coding, and trying to figure things out. I'm creating a listview dynamically as shown below (and then disabling items dynamically also) - you'll notice that there's no xml file for the activity itself, just for the listitem. What I'd like to do is add a static header to the page. Could someone explain to me how I can modify the code below to EITHER add this programatically within the java file, before the listView, OR edit the code below so that it targets a listView within an xml file! Help would be much appreciated!!! public class Start extends ListActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); DataBaseHelper myDbHelper = new DataBaseHelper(null); myDbHelper = new DataBaseHelper(this); try { myDbHelper.openDataBase(); }catch(SQLException sqle){ throw sqle; } ArrayList<String> categoryList = new ArrayList<String>(); Cursor cur = myDbHelper.getAllCategories(); cur.moveToFirst(); while (cur.isAfterLast() == false) { if (!categoryList.contains(cur.getString(1))) { categoryList.add(cur.getString(1)); } cur.moveToNext(); } cur.close(); Collections.sort(categoryList); setListAdapter(new ArrayAdapter<String>(this, R.layout.listitem, categoryList) { @Override public View getView(int position, View convertView, ViewGroup parent) { View view = super.getView(position, convertView, parent); if(Arrays.asList(checkArray3).contains(String.valueOf(position))){ view.setEnabled(false); } else { view.setEnabled(true); } return view; } }); } @Override protected void onListItemClick(ListView l, View v, int position, long id) { if(v.isEnabled()) { String clickedCat = l.getItemAtPosition(position).toString(); Toast.makeText(this, clickedCat, Toast.LENGTH_SHORT).show(); finish(); Intent myIntent = new Intent(getApplicationContext(), Questions.class); myIntent.putExtra("passedCategory", clickedCat); myIntent.putExtra("startTrigger", "go"); startActivity(myIntent); } } }

    Read the article

  • ViewGroup{TextView,...}.getMeasuredHeight gives wrong value is smaller than real height.

    - by Dewr
    ViewGroup(the ViewGroup is containing TextViews having long text except line-feed-character).getMeasuredHeight returns wrong value... that is smaller than real height. how to get rid of this problem? here is the java code: ;public static void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) { // pre-condition return; } int totalHeight = 0; int count = listAdapter.getCount(); for (int i = 0; i < count; i++) { View listItem = listAdapter.getView(i, null, listView); listItem.measure(View.MeasureSpec.AT_MOST, View.MeasureSpec.UNSPECIFIED); totalHeight += listItem.getMeasuredHeight(); } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); listView.setLayoutParams(params); } ; and here is the list_item_comments.xml:; {RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" } {RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="8dip" android:layout_marginRight="8dip" } {TextView android:id="@+id/list_item_comments_nick" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="16sp" style="@style/WhiteText" /} {TextView android:id="@+id/list_item_comments_time" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:textSize="16sp" style="@style/WhiteText" /} {TextView android:id="@+id/list_item_comments_content" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/list_item_comments_nick" android:autoLink="all" android:textSize="24sp" style="@style/WhiteText" /} {/RelativeLayout} {/RelativeLayout} ;

    Read the article

1 2 3  | Next Page >