Search Results

Search found 202 results on 9 pages for 'arrayadapter'.

Page 1/9 | 1 2 3 4 5 6 7 8 9  | Next Page >

  • ArrayAdapter need to be clear even i am creating a new one

    - by Roi
    Hello I'm having problems understanding how the ArrayAdapter works. My code is working but I dont know how.(http://amy-mac.com/images/2013/code_meme.jpg) I have my activity, inside it i have 2 private classes.: public class MainActivity extends Activity { ... private void SomePrivateMethod(){ autoCompleteTextView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, new ArrayList<String>(Arrays.asList("")))); autoCompleteTextView.addTextChangedListener(new MyTextWatcher()); } ... private class MyTextWatcher implements TextWatcher { ... } private class SearchAddressTask extends AsyncTask<String, Void, String[]> { ... } } Now inside my textwatcher class i call the search address task: @Override public void afterTextChanged(Editable s) { new SearchAddressTask().execute(s.toString()); } So far so good. In my SearchAddressTask I do some stuff on doInBackground() that returns the right array. On the onPostExecute() method i try to just modify the AutoCompleteTextView adapter to add the values from the array obtained in doInBackground() but the adapter cannot be modified: NOT WORKING CODE: protected void onPostExecute(String[] addressArray) { ArrayAdapter<String> adapter = (ArrayAdapter<String>) autoCompleteDestination.getAdapter(); adapter.clear(); adapter.addAll(new ArrayList<String>(Arrays.asList(addressArray))); adapter.notifyDataSetChanged(); Log.d("SearchAddressTask", "adapter isEmpty : " + adapter.isEmpty()); // Returns true!!??! } I dont get why this is not working. Even if i run it on UI Thread... I kept investigating, if i recreate the arrayAdapter, is working in the UI (Showing the suggestions), but i still need to clear the old adapter: WORKING CODE: protected void onPostExecute(String[] addressArray) { ArrayAdapter<String> adapter = (ArrayAdapter<String>) autoCompleteDestination.getAdapter(); adapter.clear(); autoCompleteDestination.setAdapter(new ArrayAdapter<String>(NewDestinationActivity.this,android.R.layout.simple_spinner_dropdown_item, new ArrayList<String>(Arrays.asList(addressArray)))); //adapter.notifyDataSetChanged(); // no needed Log.d("SearchAddressTask", "adapter isEmpty : " + adapter.isEmpty()); // keeps returning true!!??! } So my question is, what is really happening with this ArrayAdapter? why I cannot modify it in my onPostExecute()? Why is working in the UI if i am recreating the adapter? and why i need to clear the old adapter then? I dont know there are so many questions that I need some help in here!! Thanks!!

    Read the article

  • How to override filter in android's ArrayAdapter?

    - by Mike
    I have an ArrayAdapter wrapped around an ArrayList of custom objects. I'd like to write a custom filter for that adapter so that when I call getListAdapter().getFilter().filter("abc") the list will get filtered by an arbitrary transformation of "abc". I thought I would just try to override ArrayAdapter.getFilter(), but that requires I re-implement the private ArrayAdapter.ArrayFilter which requires access to a bunch of ArrayAdapter's private instances. What's the simplest way to do this?

    Read the article

  • How to avoid re-drawing all views in an ArrayAdapter

    - by Hamy
    Hey all, I have an ArrayAdapter powering a ListView. I would like to change the data behind the ArrayAdapter and update the ListView's. Sounds like notifyDataSetChanged(); would be exactly what I am looking for, but it updates the entire ListView, and I would prefer to update on a row-by-row basis. Is there a way to do this with ArrayAdapter, or do I need to manage my data some other way if I want this functionality?

    Read the article

  • Need help with a custom Spinner/ArrayAdapter setup

    - by MisterSquonk
    I have a WeatherSpinner class which extends Spinner. The class shows region names which I originally did using an ArrayAdapter<String> but I now want to use ArrayAdapter<Locale>(Locale is an abstract 'empty' class of my own). I'm getting a ClassCastException when trying to populate my ArrayAdapter with the following... protected ArrayList<?> theList; protected ArrayAdapter<Locale> aa = null; ... protected void updateContents(ArrayList<?> list, int selectedItem) { theList = list; // Exception thrown on next line aa = new ArrayAdapter<Locale>(theContext, android.R.layout.simple_spinner_item, (Locale[]) theList.toArray()); ... } I'm passing a RegionList object into updateContents() as the 'list' parameter and RegionList extends ArrayList<Region>, and Region extends Locale. I've also overriden Region's toString() method to return a valid String. What am I not seeing here? Am I wrong about the way ArrayList<?>.toArray() works?

    Read the article

  • how to add item to Spinner's ArrayAdapter?

    - by allen-c
    i had a EditText , a button and a spinner . When click the button , the spinner will add a new item with name you entered in the EditText. But here is the question, my adapter.add() method seems doesn't work...here is my code: public class Spr extends Activity { Button bt1; EditText et; ArrayAdapter<CharSequence> adapter; Spinner spinner; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); bt1 = (Button)this.findViewById(R.id.bt1); et = (EditText)this.findViewById(R.id.et); spinner = (Spinner)this.findViewById(R.id.spr); adapter = ArrayAdapter.createFromResource( this, R.array.planets_array, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); bt1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String temp = et.getText().toString(); adapter.add(temp); adapter.notifyDataSetChanged(); spinner.setAdapter(adapter); } }); spinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener(){ @Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { Toast.makeText(parent.getContext(), "The planet is " + parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show(); } @Override public void onNothingSelected(AdapterView<?> arg0) { }}); } }

    Read the article

  • ArrayAdapter and android:textFilterEnabled

    - by TiGer
    Hi there, I have created a layout which includes a ListView... The data shown within this ListView isn't too complicated, it's mostly an Array which is passed when the extended Activity is started... The rows themselves exist out of an icon and a text, thus an ImageView and a TextView... To fill up the ListView I use an ArrayAdapter simply because an Array is passed containing all the text-items that should be shown.. Now I'd like to actually be able to filter those, thus I found the android:textFilterEnabled paramater to add on the ListView xml declaration... Now a search field is shown nicely but when I enter some letters it won't filter but it will simply delete the whole list... I found out that that's because the textfilter has no idea what it should filter... So now my question is : I know I need to tell the textfilter what it should filter, I also still have my array filled with the text that should get filtered so how do i couple those two ??? I have seen examples extending a CursorAdapter, but again, I don't have a Cursor, I don't want to do calls to a DB I want to re-utilize my Array with data and obviously the ArrayAdapter itself so that the data will be represented decently on screen (i.e with my ImageView and TextView layout)... Thanks in advance for any help/pointers/tips/code...

    Read the article

  • Custom filtering in Android using ArrayAdapter

    - by Alxandr
    I'm trying to filter my ListView which is populated with this ArrayAdapter: package me.alxandr.android.mymir.adapters; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.Set; import me.alxandr.android.mymir.R; import me.alxandr.android.mymir.model.Manga; import android.content.Context; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.Filter; import android.widget.SectionIndexer; import android.widget.TextView; public class MangaListAdapter extends ArrayAdapter<Manga> implements SectionIndexer { public ArrayList<Manga> items; public ArrayList<Manga> filtered; private Context context; private HashMap<String, Integer> alphaIndexer; private String[] sections = new String[0]; private Filter filter; private boolean enableSections; public MangaListAdapter(Context context, int textViewResourceId, ArrayList<Manga> items, boolean enableSections) { super(context, textViewResourceId, items); this.filtered = items; this.items = filtered; this.context = context; this.filter = new MangaNameFilter(); this.enableSections = enableSections; if(enableSections) { alphaIndexer = new HashMap<String, Integer>(); for(int i = items.size() - 1; i >= 0; i--) { Manga element = items.get(i); String firstChar = element.getName().substring(0, 1).toUpperCase(); if(firstChar.charAt(0) > 'Z' || firstChar.charAt(0) < 'A') firstChar = "@"; alphaIndexer.put(firstChar, i); } Set<String> keys = alphaIndexer.keySet(); Iterator<String> it = keys.iterator(); ArrayList<String> keyList = new ArrayList<String>(); while(it.hasNext()) keyList.add(it.next()); Collections.sort(keyList); sections = new String[keyList.size()]; keyList.toArray(sections); } } @Override public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; if(v == null) { LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.mangarow, null); } Manga o = items.get(position); if(o != null) { TextView tt = (TextView) v.findViewById(R.id.MangaRow_MangaName); TextView bt = (TextView) v.findViewById(R.id.MangaRow_MangaExtra); if(tt != null) tt.setText(o.getName()); if(bt != null) bt.setText(o.getLastUpdated() + " - " + o.getLatestChapter()); if(enableSections && getSectionForPosition(position) != getSectionForPosition(position + 1)) { TextView h = (TextView) v.findViewById(R.id.MangaRow_Header); h.setText(sections[getSectionForPosition(position)]); h.setVisibility(View.VISIBLE); } else { TextView h = (TextView) v.findViewById(R.id.MangaRow_Header); h.setVisibility(View.GONE); } } return v; } @Override public void notifyDataSetInvalidated() { if(enableSections) { for (int i = items.size() - 1; i >= 0; i--) { Manga element = items.get(i); String firstChar = element.getName().substring(0, 1).toUpperCase(); if(firstChar.charAt(0) > 'Z' || firstChar.charAt(0) < 'A') firstChar = "@"; alphaIndexer.put(firstChar, i); } Set<String> keys = alphaIndexer.keySet(); Iterator<String> it = keys.iterator(); ArrayList<String> keyList = new ArrayList<String>(); while (it.hasNext()) { keyList.add(it.next()); } Collections.sort(keyList); sections = new String[keyList.size()]; keyList.toArray(sections); super.notifyDataSetInvalidated(); } } public int getPositionForSection(int section) { if(!enableSections) return 0; String letter = sections[section]; return alphaIndexer.get(letter); } public int getSectionForPosition(int position) { if(!enableSections) return 0; int prevIndex = 0; for(int i = 0; i < sections.length; i++) { if(getPositionForSection(i) > position && prevIndex <= position) { prevIndex = i; break; } prevIndex = i; } return prevIndex; } public Object[] getSections() { return sections; } @Override public Filter getFilter() { if(filter == null) filter = new MangaNameFilter(); return filter; } private class MangaNameFilter extends Filter { @Override protected FilterResults performFiltering(CharSequence constraint) { // NOTE: this function is *always* called from a background thread, and // not the UI thread. constraint = constraint.toString().toLowerCase(); FilterResults result = new FilterResults(); if(constraint != null && constraint.toString().length() > 0) { ArrayList<Manga> filt = new ArrayList<Manga>(); ArrayList<Manga> lItems = new ArrayList<Manga>(); synchronized (items) { Collections.copy(lItems, items); } for(int i = 0, l = lItems.size(); i < l; i++) { Manga m = lItems.get(i); if(m.getName().toLowerCase().contains(constraint)) filt.add(m); } result.count = filt.size(); result.values = filt; } else { synchronized(items) { result.values = items; result.count = items.size(); } } return result; } @SuppressWarnings("unchecked") @Override protected void publishResults(CharSequence constraint, FilterResults results) { // NOTE: this function is *always* called from the UI thread. filtered = (ArrayList<Manga>)results.values; notifyDataSetChanged(); } } } However, when I call filter('test') on the filter nothing happens at all (or the background-thread is run, but the list isn't filtered as far as the user conserns). How can I fix this?

    Read the article

  • ListView in ArrayAdapter order get's mixed up when scrolling

    - by Dan B
    Hi, I have a ListView in a custom ArrayAdapter that displays an icon ImageView and a TextView in each row. When I make the list long enough to let you scroll through it, the order starts out right, but when I start to scroll down, some of the earlier entries start re-appearing. If I scroll back up, the old order changes. Doing this repeatedly eventually causes the entire list order to be seemingly random. So scrolling the list is either causing the child order to change, or the drawing is not refreshing correctly. What could cause something like this to happen? I need the order the items are displayed to the user to be the same order they are added to the ArrayList, or at LEAST to remain in one static order. If I need to provide more detailed information, please let me know. Any help is appreciated. Thanks.

    Read the article

  • ArrayAdapter throwing ArrayIndexOutOfBoundsException

    - by alex
    I am getting an error of an array out of bounce error when i am using my custom array adapter. I am wondering if there are any coding errors I have overlooked. Here is the error log 06-10 20:21:53.254: E/AndroidRuntime(315): FATAL EXCEPTION: main 06-10 20:21:53.254: E/AndroidRuntime(315): java.lang.RuntimeException: Unable to start activity ComponentInfo{alex.android.galaxy.tab.latest/alex.android.galaxy.tab.latest.Basic_db_output}: java.lang.ArrayIndexOutOfBoundsException 06-10 20:21:53.254: E/AndroidRuntime(315): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 06-10 20:21:53.254: E/AndroidRuntime(315): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 06-10 20:21:53.254: E/AndroidRuntime(315): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 06-10 20:21:53.254: E/AndroidRuntime(315): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 06-10 20:21:53.254: E/AndroidRuntime(315): at android.os.Handler.dispatchMessage(Handler.java:99) 06-10 20:21:53.254: E/AndroidRuntime(315): at android.os.Looper.loop(Looper.java:123) 06-10 20:21:53.254: E/AndroidRuntime(315): at android.app.ActivityThread.main(ActivityThread.java:4627) 06-10 20:21:53.254: E/AndroidRuntime(315): at java.lang.reflect.Method.invokeNative(Native Method) 06-10 20:21:53.254: E/AndroidRuntime(315): at java.lang.reflect.Method.invoke(Method.java:521) 06-10 20:21:53.254: E/AndroidRuntime(315): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 06-10 20:21:53.254: E/AndroidRuntime(315): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 06-10 20:21:53.254: E/AndroidRuntime(315): at dalvik.system.NativeStart.main(Native Method) 06-10 20:21:53.254: E/AndroidRuntime(315): Caused by: java.lang.ArrayIndexOutOfBoundsException 06-10 20:21:53.254: E/AndroidRuntime(315): at alex.android.galaxy.tab.latest.Basic_db_output.onCreate(Basic_db_output.java:44) 06-10 20:21:53.254: E/AndroidRuntime(315): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 06-10 20:21:53.254: E/AndroidRuntime(315): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) I am basing my code example on this How to use ArrayAdapter<myClass> ArrayList list = new ArrayList(); for(int i=1; i <= 3; i++) { Reader reader = new ResultsReader("android_galaxy_tab_latest/src/quiz"+i+".txt"); reader.read(); String str = ((ResultsReader)reader).getInput(); String data[] = str.split("<.>"); Question q = new Question(); q.question = data[0]; q.answer = Integer.parseInt(data[1]); q.choice1 = data[2]; q.choice2 = data[3]; q.choice3 = data[4]; list.add(q); }

    Read the article

  • Android How do i overwrite the filter for my ArrayAdapter?

    - by alan
    Hey guys my first post here... Im trying to write a custom filter to filter the arraylist in my arrayadapter such that my listview is filtered when i click on the button. For instance when i click on my button public void onClick(View arg0) { String abc = "abc"; m_adapter.getFilter().filter(abc); } However, when i click on my button, my app terminate unexpectedly. Here is my code for the arrayadapter and filter. Please help me. package com.ntu.rosemobile.searchlist; public class ResultsAdapter extends ArrayAdapter<SearchItem> implements Filterable{ public ArrayList<SearchItem> subItems; public ArrayList<SearchItem> allItems; private LayoutInflater inflater; private PTypeFilter filter; public ResultsAdapter(Context context, int textViewResourceId, ArrayList<SearchItem> items) { super(context, textViewResourceId, items); this.subItems = items; this.allItems = this.subItems; inflater= LayoutInflater.from(context); } @Override public Filter getFilter() { if (filter == null){ filter = new PTypeFilter(); } return filter; } //@Override public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; if (v == null) { v = inflater.inflate(R.layout.listrow, null); } SearchItem o = subItems.get(position); if (o != null) { TextView pname = (TextView) v.findViewById(R.id.productname); TextView neg = (TextView) v.findViewById(R.id.negNum); TextView pos = (TextView) v.findViewById(R.id.posNum); TextView neu = (TextView) v.findViewById(R.id.neuNum); WebImageView productPhoto = (WebImageView)v.findViewById(R.id.pPhoto); if(productPhoto!=null){ productPhoto.setImageUrl(o.getImageUrl().toString()); productPhoto.loadImage(); } if(pname!= null){ pname.setText(o.getProductName().toString()); } if (neg != null) { String a = "" + o.getNegativeReviews(); neg.setText(a); } if(neu != null){ String a = "" + o.getNeutralReviews(); neu.setText(a); } if(pos != null){ String a = "" + o.getPositiveReviews(); pos.setText(a); } } return v; } private class PTypeFilter extends Filter{ @SuppressWarnings("unchecked") @Override protected void publishResults(CharSequence prefix, FilterResults results) { // NOTE: this function is *always* called from the UI thread. subItems = (ArrayList<SearchItem>)results.values; notifyDataSetChanged(); } @SuppressWarnings("unchecked") protected FilterResults performFiltering(CharSequence prefix) { // NOTE: this function is *always* called from a background thread, and // not the UI thread. FilterResults results = new FilterResults(); ArrayList<SearchItem> i = new ArrayList<SearchItem>(); if (prefix!= null && prefix.toString().length() > 0) { for (int index = 0; index < allItems.size(); index++) { SearchItem si = allItems.get(index); if(si.getPType().compareTo(prefix.toString()) == 0){ i.add(si); } } results.values = i; results.count = i.size(); } else{ synchronized (allItems){ results.values = allItems; results.count = allItems.size(); } } return results; } } }

    Read the article

  • Computation on db data then list them using either SimpleCursorAdapter or ArrayAdapter

    - by kc2uno
    Hi all, I juststarted programming in android a few weeks ago, so I am not entirely sure how to deal with listing values. Please help me out! I have some questions regarding displaying data sets from db in a list. Currently I have a cursor returned by my db points to a list of rows and I want display 2 columns values in a single row of the list. The row xml looks like this: <TextView android:id="@+id/text1" android:textSize="16sp" android:textStyle="bold" android:layout_width="fill_parent" android:layout_height="wrap_content"/> <TextView android:id="@+id/text2" android:textSize="14sp" android:layout_width="fill_parent" android:layout_height="wrap_content"/> so I was thinking using simplecursoradapter which supposedly makes my life easier by displaying the data in a list. However that is only true if I want to display the raw data. For the purpose of my program I need to do some computations on the raw data sets, then display them. I am not sure how to do that using SimpleCursorAdapter. Here's how I display the raw data: String[] from = new String[]{BtDbAdapter.KEY_EX_TYPE,BtDbAdapter.KEY_EX_TIMESTAMP}; int[] to = new int[]{R.id.text1, R.id.text2}; // Now create a simple cursor adapter and set it to display SimpleCursorAdapter records = new SimpleCursorAdapter(this, R.layout.exset_row, mExsetCursor, from, to); setListAdapter(records); Is there a way to do computation on the data in those rows before I bind it with the SimpleCursorAdapter? I was trying to use an alternative way of doing this by using arraylist and arrayadapter, but that way I dont know to how achieve displaying 2 items in a single row. This is my code for using arrayadapter which only display 1 text in a row instead of 2 textviews in a row: //fill in the array timestamp_arr = new ArrayList<String>(); type_arr = new ArrayList<String>(); fillRecord(); Log.d(TAG,"setting now in recordlist"); setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item,timestamp_arr)); setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item2,type_arr)); It's very obvious that it only displays one textview in a row because I set the second arrayadapter overwrites the first one! I was trying to use R.id.text1 and R.id.text2 for them, but it gave me some errors saying 04-23 01:40:58.658: ERROR/AndroidRuntime(3309): android.content.res.Resources$NotFoundException: Resource ID #0x7f070008 type #0x12 is not valid I believe the second method can achieve this, but I'm not sure how do deal with the layout problems, so if you any suggestions, please post them out. Thank you!!

    Read the article

  • ListView with Custom ArrayAdapter not updating

    - by Intelwalk
    I am currently trying to return a custom view of a textview, chrono, and checkbox. I have overriden the getView method but I am not sure if I did it correctly. I would appreciate some comments on the arrayadapter. It currently does not update in my application. Thanks! main java public class TaskTracker extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button addButton; addButton=(Button)findViewById(R.id.button1); ListView myListView= (ListView)findViewById(R.id.listView1); final EditText myEditText= (EditText)findViewById(R.id.editText1) ; //final ArrayList<String> taskitems = new ArrayList<String>(); final TTAdapterView aa = new TTAdapterView(this); // aa = new ArrayAdapter<String>(this, 0); myListView.setAdapter(aa); addButton.setOnClickListener(new OnClickListener(){ public void onClick(View v){ aa.add(myEditText.getText().toString()); //taskitems.add(count, myEditText.getText().toString()); aa.notifyDataSetChanged(); myEditText.setText(""); myEditText.requestFocus(); } }); } } ArrayAdapter public class TTAdapterView extends ArrayAdapter<String> { public View v; public TTAdapterView(Context context){ super(context,R.layout.row); } @Override public View getView(int position, View convertView, ViewGroup parent){ this.v = convertView; if(v==null){ LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.row, null); } return v; }

    Read the article

  • ArrayAdapter Help?

    - by ramsbh
    Hi i want to display a list view in my application. Each row should contains a text and an image. i have used ArrayAdapter to display this, but how to insert an image after the text.Please help ? String lvr[]={"Android","iPhone","BlackBerry","AndroidPeople"}; super.onCreate(savedInstanceState); setContentView(R.layout.main); list1 = (ListView) findViewById(R.id.cg_listview1); list1.setAdapter(new ArrayAdapter<String>(this,R.layout.alerts , lvr)); Here alerts is my layout contains only textView.

    Read the article

  • Android: databinding when using a ArrayAdapter: possible?

    - by Peterdk
    I need some simple databinding for a Spinner. I want to display 2 items for each dropdownitem. So when the user clicks the spinner I get a list like: ------------------- Name 123456 ------------------- Name 123456 ------------------- I understand this can be done when using a Cursor, according to the databinding info on android dev. Like: SimpleCursorAdapter adapter2 = new SimpleCursorAdapter(this, R.layout.my_custom_spinner_item_layout, cur, new String[] {People.NAME, People.ID}, new int[] {android.R.id.text1, android.R.id.text2}); However, I don't get my data from a database, so I don't use a cursor, I use a ArrayAdapter. Unfortunately it looks like there is no support for databinding with this adapter. Is there a way to do this?

    Read the article

  • Android/Java Beginner: Overriding ArrayAdapter's getView

    - by Preformed Cone
    Firstly I am new to android and Java so this is a beginners question. I have some code that overrides the ArrayAdapter's getView method. Here is the code public View getView(int position, View convertView, ViewGroup parent) { TextView label = (TextView)convertView; if (convertView == null) { convertView = new TextView(ctxt); label = (TextView)convertView; } label.setText(items[position]); return (convertView); } My question is: why does label.setText(items[position]); affect the convertView return value? How are they related / linked?

    Read the article

  • How to get the value of an item from database and set it as the spinner value

    - by kulPrins
    I have a database and the database populates a listview. when i long press a list item from the listview i get a context menu where i have the option to edit. When the edit option is clicked i open an activity and get all the values of the respective fields from the database. Now, here I want to get a value from the database and show it in the spinner. the spinner already has these values and is getting populated from the database... I have tried the following, but i get an error saying I can't cast a SimpleCursorAdapter to an ArrayAdapter.. String osub = cursor.getString(Database.INDEX_SUBJECT); Cursor cs = mDBS.querySub(osub); String subs = cs.getString(DatabaseSub.INDEX_SSUBJECT); if(cs!=null){ ArrayAdapter<String> myAdap = (ArrayAdapter<String>) subSpinner.getAdapter(); //cast to an ArrayAdapter int spinnerPosition = myAdap.getPosition(subs); //set the default according to value subSpinner.setSelection(spinnerPosition); Please tell me how to do this.. Thank you.. I am relatively new so please let me know if I am overlooking something. Thanks.. EDIT querySub method public Cursor querySub(String sub) throws SQLException { Cursor cursor = mDatabase.query(true, DATABASE_TABLE, sAllColumns, "ssub like " + "'" + sub + "'", null, null, null, null, null); if (cursor.moveToNext()) { return cursor; } cursor.moveToFirst(); return cursor; } Error Log 06-05 12:11:14.144: E/AndroidRuntime(775): FATAL EXCEPTION: main 06-05 12:11:14.144: E/AndroidRuntime(775): java.lang.RuntimeException: Unable to start activity ComponentInfo{an.droid.kit/an.droid.kit.DetailsActivity}: java.lang.ClassCastException: android.widget.SimpleCursorAdapter cannot be cast to android.widget.ArrayAdapter 06-05 12:11:14.144: E/AndroidRuntime(775): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956) 06-05 12:11:14.144: E/AndroidRuntime(775): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 06-05 12:11:14.144: E/AndroidRuntime(775): at android.app.ActivityThread.access$600(ActivityThread.java:123) 06-05 12:11:14.144: E/AndroidRuntime(775): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) 06-05 12:11:14.144: E/AndroidRuntime(775): at android.os.Handler.dispatchMessage(Handler.java:99) 06-05 12:11:14.144: E/AndroidRuntime(775): at android.os.Looper.loop(Looper.java:137) 06-05 12:11:14.144: E/AndroidRuntime(775): at android.app.ActivityThread.main(ActivityThread.java:4424) 06-05 12:11:14.144: E/AndroidRuntime(775): at java.lang.reflect.Method.invokeNative(Native Method) 06-05 12:11:14.144: E/AndroidRuntime(775): at java.lang.reflect.Method.invoke(Method.java:511) 06-05 12:11:14.144: E/AndroidRuntime(775): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 06-05 12:11:14.144: E/AndroidRuntime(775): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 06-05 12:11:14.144: E/AndroidRuntime(775): at dalvik.system.NativeStart.main(Native Method) 06-05 12:11:14.144: E/AndroidRuntime(775): Caused by: java.lang.ClassCastException: android.widget.SimpleCursorAdapter cannot be cast to android.widget.ArrayAdapter 06-05 12:11:14.144: E/AndroidRuntime(775): at an.droid.kit.DetailsActivity.dbToUI(DetailsActivity.java:217) 06-05 12:11:14.144: E/AndroidRuntime(775): at an.droid.kit.DetailsActivity.onCreate(DetailsActivity.java:104) 06-05 12:11:14.144: E/AndroidRuntime(775): at android.app.Activity.performCreate(Activity.java:4465) 06-05 12:11:14.144: E/AndroidRuntime(775): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 06-05 12:11:14.144: E/AndroidRuntime(775): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) 06-05 12:11:14.144: E/AndroidRuntime(775): ... 11 more

    Read the article

  • AutoCompleteTextView not displaying result even when the ArrayAdapter is updated

    - by cant0na
    I'm trying to get an AutoCompleteTextView(ACTV) to display results I'm a getting from a network resource. I have set the completion-treshold to 2 and I can see that the request is fired when I enter to characters. The result I am getting is the correct one. Lets say I write "ca", and I get the result "car" as an autocompletion. I have a callback function which receives the result from an AsyncTask and puts the result into the ArrayAdapter. Then I call .showDropDown() on the ACTV and an empty dropdown is shown (half the size of a normal element). Then if I enter the last letter "r" and the ACTV shows "car", the dropdown is shown and the result is suddenly in the list. The same happens if I have entered two characters (which returns a valid result), and the remove the last letter. When the letter is removed, "car" is shown as an autocompletion value. Has anyone had this problem? It looks like the adapter is filled with the result, but the result does not show until the next action I do. I have also tried to run .notifyDataSetChanged() after I have added the result to the adapter, but that should not be needed, or?

    Read the article

  • Spinner cannot load an integer array?

    - by Adam
    I have an application, which has a Spinner that I want populated with some numbers (4,8,12,16). I created an integer-array object in strings.xml with the items mentioned above, set the entries of the Spinner to the integer-array, and when I run the app I get: 04-19 23:38:48.016: ERROR/AndroidRuntime(10193): java.lang.NullPointerException 04-19 23:38:48.016: ERROR/AndroidRuntime(10193): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:355) 04-19 23:38:48.016: ERROR/AndroidRuntime(10193): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323) 04-19 23:38:48.016: ERROR/AndroidRuntime(10193): at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:198) 04-19 23:38:48.016: ERROR/AndroidRuntime(10193): at android.view.View.measure(View.java:7965) 04-19 23:38:48.016: ERROR/AndroidRuntime(10193): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989) 04-19 23:38:48.016: ERROR/AndroidRuntime(10193): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:888) 04-19 23:38:48.016: ERROR/AndroidRuntime(10193): at android.widget.LinearLayout.measureVertical(LinearLayout.java:350) 04-19 23:38:48.016: ERROR/AndroidRuntime(10193): at android.widget.LinearLayout.onMeasure(LinearLayout.java:278) 04-19 23:38:48.016: ERROR/AndroidRuntime(10193): at android.view.View.measure(View.java:7965) 04-19 23:38:48.016: ERROR/AndroidRuntime(10193): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989) 04-19 23:38:48.016: ERROR/AndroidRuntime(10193): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 04-19 23:38:48.016: ERROR/AndroidRuntime(10193): at android.view.View.measure(View.java:7965) 04-19 23:38:48.016: ERROR/AndroidRuntime(10193): at android.widget.LinearLayout.measureVertical(LinearLayout.java:464) 04-19 23:38:48.016: ERROR/AndroidRuntime(10193): at android.widget.LinearLayout.onMeasure(LinearLayout.java:278) 04-19 23:38:48.016: ERROR/AndroidRuntime(10193): at android.view.View.measure(View.java:7965) 04-19 23:38:48.016: ERROR/AndroidRuntime(10193): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989) 04-19 23:38:48.016: ERROR/AndroidRuntime(10193): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 04-19 23:38:48.016: ERROR/AndroidRuntime(10193): at android.view.View.measure(View.java:7965) 04-19 23:38:48.016: ERROR/AndroidRuntime(10193): at android.view.ViewRoot.performTraversals(ViewRoot.java:763) 04-19 23:38:48.016: ERROR/AndroidRuntime(10193): at android.view.ViewRoot.handleMessage(ViewRoot.java:1632) 04-19 23:38:48.016: ERROR/AndroidRuntime(10193): at android.os.Handler.dispatchMessage(Handler.java:99) 04-19 23:38:48.016: ERROR/AndroidRuntime(10193): at android.os.Looper.loop(Looper.java:123) 04-19 23:38:48.016: ERROR/AndroidRuntime(10193): at android.app.ActivityThread.main(ActivityThread.java:4310) 04-19 23:38:48.016: ERROR/AndroidRuntime(10193): at java.lang.reflect.Method.invokeNative(Native Method) 04-19 23:38:48.016: ERROR/AndroidRuntime(10193): at java.lang.reflect.Method.invoke(Method.java:521) 04-19 23:38:48.016: ERROR/AndroidRuntime(10193): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 04-19 23:38:48.016: ERROR/AndroidRuntime(10193): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 04-19 23:38:48.016: ERROR/AndroidRuntime(10193): at dalvik.system.NativeStart.main(Native Method) As soon as I changed the array to a string-array, this works fine. Is this normal? I realize that I can (and will) just convert the string array values to an int, but it seems weird that I have to. Thanks!

    Read the article

  • ArrayAdapter and ListView - ArrayIndexOutOfBoundsException

    - by synic
    I'm really hoping someone can help me out with this one. I've been stuck on it forever. Occasionally, when someone is using my app, it'll force close with this exception: java.lang.ArrayIndexOutOfBoundsException at android.widget.AbsListView$RecycleBin.addScrapView(AbsListView.java:3572) at android.widget.AbsListView.trackMotionScroll(AbsListView.java:2487) at android.widget.AbsListView.onTouchEvent(AbsListView.java:2001) at android.widget.ListView.onTouchEvent(ListView.java:3234) at android.view.View.dispatchTouchEvent(View.java:3709) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:874) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924) at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1695) at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1116) at android.app.Activity.dispatchTouchEvent(Activity.java:2068) at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1679) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924) at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1695) at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1116) at android.app.Activity.dispatchTouchEvent(Activity.java:2068) at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1679) at android.view.ViewRoot.handleMessage(ViewRoot.java:1697) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:123) at android.app.ActivityThread.main(ActivityThread.java:4568) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:521) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) at dalvik.system.NativeStart.main(Native Method) However, I cannot figure out why. It's relatively rare, non-reproducable, and the stacktrace is completely unhelpful because it doesn't include any of my code. Is it a bug in Android itself?

    Read the article

  • Android - Display HTML Formatted String

    - by Soren
    I need an example of how to display the strings that I have marked up with simple html into a TextView. I have found "Spanned fromHtml(String source)", but I don't know how to plug it into my java code. Here is my Java: package com.SorenWinslow.TriumphHistory; import android.app.ListActivity; import android.os.Bundle; import android.widget.ArrayAdapter; public class TriumphHistory extends ListActivity { String[] HistoryList; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ArrayAdapter<String> adapter; HistoryList = getResources().getStringArray(R.array.history); adapter = new ArrayAdapter<String> (this,R.layout.historylistlayout,HistoryList); setListAdapter(adapter); } } Here is a sample of history: <?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="history"> <item><b>1883</b><br/>Some stuff happened</item> <item><b>1884</b><br/>Some more stuff happened <i>before</i> the other stuff </item> <resources> Here is my historylistlayout.xml: <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:gravity="center_vertical" android:textColor="#ffffff" android:background="#000050" android:layout_marginTop="5px" android:minHeight="?android:attr/listPreferredItemHeight" android:padding="3px" android:textSize="8pt" android:layout_gravity="top|left"/> And here is my main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:textColor="#ffffff" android:background="#000080" android:isScrollContainer="true" android:layout_height="fill_parent" android:layout_width="fill_parent" android:scrollbarStyle="insideOverlay"> <ListView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="wrap_content" android:clickable="true" android:dividerHeight="1px"/> </LinearLayout>

    Read the article

  • Andorid - Display HTML Formatted String

    - by Soren
    I need an example how to display the strings that I have marked up with simple html into a TextView. I have found "Spanned fromHtml(String source)", but I don't know how to plug it into my java code. Here is my Java: package com.SorenWinslow.TriumphHistory; import android.app.ListActivity; import android.os.Bundle; import android.widget.ArrayAdapter; public class TriumphHistory extends ListActivity { String[] HistoryList; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ArrayAdapter<String> adapter; HistoryList = getResources().getStringArray(R.array.history); adapter = new ArrayAdapter<String> (this,R.layout.historylistlayout,HistoryList); setListAdapter(adapter); } } Here is a sample of history: <?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="history"> <item><b>1883</b><br/>Some stuff happened</item> <item><b>1884</b><br/>Some more stuff happened <i>before</i> the other stuff </item> <resources> Here is my historylistlayout.xml: <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:gravity="center_vertical" android:textColor="#ffffff" android:background="#000050" android:layout_marginTop="5px" android:minHeight="?android:attr/listPreferredItemHeight" android:padding="3px" android:textSize="8pt" android:layout_gravity="top|left"/> And here is my main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:textColor="#ffffff" android:background="#000080" android:isScrollContainer="true" android:layout_height="fill_parent" android:layout_width="fill_parent" android:scrollbarStyle="insideOverlay"> <ListView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="wrap_content" android:clickable="true" android:dividerHeight="1px"/> </LinearLayout>

    Read the article

  • How can I make these images download on a seperate thread?

    - by Andy Barlow
    Hello!! I have the following code running on my Android device. It works great and displays my list items wonderfully. It's also clever in the fact it only downloads the data when it's needed by the ArrayAdapter. However, whilst the download of the thumbnail is occurring, the entire list stalls and you cannot scroll until it's finished downloading. Is there any way of threading this so it'll still scroll happily, maybe show a place holder for the downloading image, finish the download, and then show? Any help with this would be really apreciated. Thank-you kindly. Andy Barlow private class CatalogAdapter extends ArrayAdapter { private ArrayList<SingleQueueResult> items; //Must research what this actually does! public CatalogAdapter(Context context, int textViewResourceId, ArrayList<SingleQueueResult> items) { super(context, textViewResourceId, items); this.items = items; } /** This overrides the getview of the ArrayAdapter. It should send back our new custom rows for the list */ @Override public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; if (v == null) { LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.mylists_rows, null); } final SingleQueueResult result = items.get(position); // Sets the text inside the rows as they are scrolled by! if (result != null) { TextView title = (TextView)v.findViewById(R.id.mylist_title); TextView format = (TextView)v.findViewById(R.id.mylist_format); title.setText(result.getTitle()); format.setText(result.getThumbnail()); // Download Images ImageView myImageView = (ImageView)v.findViewById(R.id.mylist_thumbnail); downloadImage(result.getThumbnail(), myImageView); } return v; } } // This should run in a seperate thread public void downloadImage(String imageUrl, ImageView myImageView) { try { url = new URL(imageUrl); URLConnection conn = url.openConnection(); conn.connect(); InputStream is = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); Bitmap bm = BitmapFactory.decodeStream(bis); bis.close(); is.close(); myImageView.setImageBitmap(bm); } catch (IOException e) { /* Reset to Default image on any error. */ //this.myImageView.setImageDrawable(getResources().getDrawable(R.drawable.default)); } }

    Read the article

  • How can I make these images download on a separate thread?

    - by Andy Barlow
    I have the following code running on my Android device. It works great and displays my list items wonderfully. It's also clever in the fact it only downloads the data when it's needed by the ArrayAdapter. However, whilst the download of the thumbnail is occurring, the entire list stalls and you cannot scroll until it's finished downloading. Is there any way of threading this so it'll still scroll happily, maybe show a place holder for the downloading image, finish the download, and then show? Any help with this would be really appreciated. private class CatalogAdapter extends ArrayAdapter<SingleQueueResult> { private ArrayList<SingleQueueResult> items; //Must research what this actually does! public CatalogAdapter(Context context, int textViewResourceId, ArrayList<SingleQueueResult> items) { super(context, textViewResourceId, items); this.items = items; } /** This overrides the getview of the ArrayAdapter. It should send back our new custom rows for the list */ @Override public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; if (v == null) { LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.mylists_rows, null); } final SingleQueueResult result = items.get(position); // Sets the text inside the rows as they are scrolled by! if (result != null) { TextView title = (TextView)v.findViewById(R.id.mylist_title); TextView format = (TextView)v.findViewById(R.id.mylist_format); title.setText(result.getTitle()); format.setText(result.getThumbnail()); // Download Images ImageView myImageView = (ImageView)v.findViewById(R.id.mylist_thumbnail); downloadImage(result.getThumbnail(), myImageView); } return v; } } // This should run in a seperate thread public void downloadImage(String imageUrl, ImageView myImageView) { try { url = new URL(imageUrl); URLConnection conn = url.openConnection(); conn.connect(); InputStream is = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); Bitmap bm = BitmapFactory.decodeStream(bis); bis.close(); is.close(); myImageView.setImageBitmap(bm); } catch (IOException e) { /* Reset to Default image on any error. */ //this.myImageView.setImageDrawable(getResources().getDrawable(R.drawable.default)); } }

    Read the article

1 2 3 4 5 6 7 8 9  | Next Page >