Menu
  • HOME
  • TAGS

Sorting ArrayList with objects using Comparator and Custom ArrayAdapter

android,sorting,arraylist,android-arrayadapter,comparator

Your assumption that Collections.sort( returns the sorted collection is wrong. mAdapter = new CoursesItemAdapter(getActivity(), R.layout.catalog_list_item, Collections.sort(parserJson.getCourses(), new CoursesPriceComparator())); it should be ArrayList< CoursesData > data = parserJson.getCourses(); Collections.sort(parserJson.getCourses(), new CoursesPriceComparator()) mAdapter = new CoursesItemAdapter(getActivity(), R.layout.catalog_list_item, data); Collection.sort return type is void. Check here the documentation ...

Unable to filter custom List View in android

java,android,listview,android-arrayadapter

Try This, Once you put your elements in the templist, you need to equal the arrlst from templist and reinitialize the adapter. -> @Override public void onTextChanged(CharSequence s, int start, int before, int count) { ArrayList<Employee> tempList = new ArrayList<Employee>(); for(Employee emp : arrlst){ if(emp.name.contains(s) || emp.username.contains(s)) tempList.add(emp); } //I...

Android simple ArrayAdapter from String[]

android,android-arrayadapter

The Adapter concept has to be understood first. It needs an array (or list) of objects so for each item it will find inside it, it will generate a View (when needed). Here, if you want to play with an array of String, you must tell to the ArrayAdapter that...

android - is array adapter compulsory to use?

android,android-listview,android-arrayadapter

Yes because array adapter only create the number max of visible views at any time. If your screen can only display 4 of your views, only 4 views will be created. Your views are recycled and reused with a new content in future. If you create your own views, for...

Android: Strong reference cycle using ArrayAdapter

android,android-listview,android-arrayadapter

ARC is not a real GC (Garbage Collector) that is being used by Java/Android, as such they have different behavior. One of such behavior is that for ARC it's up to the developer to break any circular references to prevent memory leak, but it's a non issue for Android, whose...

List shows as not null but ArrayAdapter throws NullPointerException

java,android,android-listview,nullpointerexception,android-arrayadapter

Your context is null. Use MainActivity.this for a context in an anon inner class of your activity.

Android ListView ArrayAdapter getting data from host activity?

android,listview,android-arrayadapter

public class CustomArrayAdapter extends ArrayAdapter<String> { String addInfo; public CustomArrayAdapter(String additionalInfo) { addInfo=additionalInfo; } } when creating object for arrayadapter, use it like below CustomArrayAdapter custAdapter=new CustomArrayAdapter("Additional Info"); ...

Android notifyDataSetChanged not working

android,listview,android-arrayadapter,notifydatasetchanged

create a method in your adapter like: public void updateList(){ notifyDataSetChanged() } and call this method when you want to refresh the list...

Unable to find TextView when populating ListView with ArrayAdapter

java,android,android-arrayadapter,listadapter

Because, TextView descriptor is part of itemView (From R.layout.activity_singletotalbet) so access using reference of itemView Like, TextView descriptor = (TextView) itemView.findViewById(R.id.no); ...

Android ArrayAdapter does not update ListView

java,android,listview,android-arrayadapter

Modify your constructor to call the super constructor with arguments: ArrayAdapter(Context context, int resource, List<T> objects) Also you don't need to override the add and addAll methods. The default implementation is just fine. Edit: To elaborate... When you call ArrayAdapter(Context context, int resource) the adapter creates an empty ArrayList for...

Extend a custom ArrayAdapter [duplicate]

java,android,android-arrayadapter

Inheritance doesn't work like you are hoping it does when you are talking about parameterized types: Even if S is a proper subtype of T Then List<S> is not a subtype of List<T> Therefore you cannot pass a List<TeamListItem> as an argument where the parameter is of type List<IconListItem>. But,...

Targeting a View within an ArrayAdapter in Android

java,android,android-activity,android-arrayadapter

I have to thank John P. and Guardanis for the major clue as to why I couldn't target the ListView's inner child. It helped changed the way I thought about the problem itself. I thought the problem was in the Adapter, but it became clear after their suggestions that it...

Adapter ListView not refreshing from Activity

android,listview,android-fragments,android-arrayadapter

Yeah, look at your code, of course, the data in your fragment is empty. Why? QueryArtistsFromSpotify queryArtistsFromSpotify = new QueryArtistsFromSpotify(this); queryArtistsFromSpotify.execute(queryString); --> this 2 lines will be run off UI thread which means that it runs on another thread. We can see that you change data right after the thread...

Array adapter and listview issues after launching Intent Service

android,android-listview,android-arrayadapter

After reading around i finally found out what i was doing wrong, mainly due to this question here and here. onHandleIntent runs on a worker thread so there really was no need for me to create an Async task in the intent service in the first place. So i replaced...

ArrayAdapter getView position is not true

java,android,listview,android-arrayadapter

try resetting the default color for the other rows if the condition is false: if(uas.size() > 0 && tinydb.getInt("selectedUA", 0) == position) { item.setBackgroundColor(Color.GREEN); } else { // e.g. item.setBackgroundColor(Color.RED); } ...

Populate Listview from a different function's ArrayAdapter - Android

android,listview,android-arrayadapter

This is what's wrong: MainActivity mainact = new MainActivity(); mainact.BuildList(alert); You can not instantiate an Activity like that, it's created from the framework. If you want to send data between Activitys, you can use intents or SharedPreferences. Example using Intent: Intent intent = new Intent(getBaseContext(), YourActivity.class); intent.putExtra("your_key", yourValue); startActivity(intent) There's...

ArrayAdapter add method casting Illegal state exception

android,exception,android-arrayadapter

You're assigning the adapter to the local variable pairedDevicesAdapter instead of to instance variable. It is local to the onCreate() method see this: ArrayAdapter<String> pairedDevicesAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1); Therefore, your pairedDevicesAdapter the one you're using to call the method 'add' is null (never initialized). to fix: on the onCreate()...

SectionIndexer shifted in mock contacts app

android,scroll,android-arrayadapter,contacts,sectionindexer

Your implementation looks okay as far as I can see. I think there are two possibilities: Your Contact.getSection() method doesn't return the right value. Actually your indexer works correctly, but it just seems working oddly to you. If the item at the very top of your screen (not of your...

How to set parent background on ArrayAdapter

java,android,xml,android-arrayadapter

Set background color to your ListItem like rowView.setBackgroundResource(R.color.yourcolor); ...

NullPointerException on ArrayList in ArrayAdapter

android,nullpointerexception,android-arrayadapter

You forgot to save the ViewHolder as a tag whenever you create a new view. The first if statement in getView() should look like: if (row == null) { LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); row = inflater.inflate(R.layout.message_list_item, parent, false); holder = new ViewHolder(); holder.wrapper = (LinearLayout) row.findViewById(R.id.wrapper); holder.countryName = (TextView)...

android: how to get and display data on an array list view

java,android,android-studio,android-arrayadapter

First of all, make sure that you have added all of your activities in your Manifest.xml <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".ViewActivity"/> <activity android:name=".AddActivity2Activity"/> Second, you have not initialized your database object in your AddActivity2Activity....

Set an item to the footer of listview

android,listview,android-arrayadapter,navigation-drawer

Please see the sample code to set the footer to a listview mListview = (ListView) mContentView.findViewById(R.id.myListView); // Inflating header and footer view to Listview ViewGroup header = (ViewGroup) inflater.inflate(R.layout.header_item, mListview,false); ViewGroup footer = (ViewGroup) inflater.inflate(R.layout.footer_item,mListview,false); //Adding view to mlist header and footer mListview.addHeaderView(header, null, false); mListview.addFooterView(footer, null, false); // Initializing...

Android ListView show different items than Adapter get

android,listview,android-arrayadapter

You use again, already created convertView, but you don't set data for current position. Simplest solution @Override public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; if (v == null) { LayoutInflater vi; vi = LayoutInflater.from(getContext()); v = vi.inflate(R.layout.task, null); } Task task = tasks.get(position); if...

ArrayAdaptor constructor not being found

android,android-arrayadapter

The problem : ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this, R.layout.connect2, previousDevices) this here is a ListFragment, get activity of this fragment for the context. Solution : ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(getActivity(), R.layout.connect2, previousDevices) ...

Android ArrayAdapter dynamic adding more data on scrolling

android,adapter,android-arrayadapter,autocompletetextview

Once try as follows Change following line if (getCount()>position && itemCount== 5) { to if (position==4) { Note : If scroll reaches 5 position then in getView() the position is 4 because the index starts with 0. If you want to add more items at the end of listview you...

piccasso square not rendering images

android,android-fragments,android-arrayadapter,android-image

Move: mGridView =(GridView) rootView.findViewById(R.id.imagesGrid);//reference to gridview ImagesGridAdapter adapter = new ImagesGridAdapter(getActivity(),mSmalImagesUrls); mGridView.setAdapter(adapter); To: @Override public void onResponse(Response response) throws IOException { try { String jsonData = response.body().string(); Log.v(TAG, jsonData); if (!response.isSuccessful()) { alertUserAboutError(); } else { mSmalImagesUrls = getCurrentDetails(jsonData); //Move it here getActivity().runOnUiThread(new Runnable(){ @Override public void...

Android ListView Adapter not working correctly

java,android,listview,android-listview,android-arrayadapter

You're passnig the applicationContext to your adapter. Pass your Activity by: artistAdapter = new itemAdapter(MainActivity.this, //Changed from ArrayAdapter<Item> R.layout.custom_listview, //R.layout.custom_listview if itemAdapter works result.toArray(new Item[] {})); ...

NullPointerException with ListView and ArrayAdapter

android,xml,listview,android-arrayadapter,runtimeexception

ok, I figured it out. I had to extend Activity and not ListActivity. I don't really understand why but it worked.

Generic Array Adapter for Alternate Row Color?

android,android-arrayadapter

I did some tweaking as includeMe suggested and its working now. I can pass my layout as dynamic. public class SpecialAdapter<T> extends ArrayAdapter<T> { private int[] colors = new int[] { 0x30FF0000, 0x300000FF }; int resource; Activity context; List<T> items; public SpecialAdapter(Activity context, int resource, List<T> items) { super(context, resource,...

IndexOutOfBoundsException issue with ArrayAdapter Class

android,android-listview,android-arrayadapter

I believe the problem is that you're not caching the correct position with the corresponding Button, so the items being removed are getting mixed up. You can set the Button's tag to the position, and retrieve it from the View passed into the onClick() method, to ensure the right one...

ListView shows wrong items on Scroll

android,listview,android-arrayadapter

I think you have a problem here @Override public View getView(int position, View convertView, ViewGroup parent) { View clist; LayoutInflater inflater = (LayoutInflater) cntxt.getSystemService(Context.LAYOUT_INFLATER_SERVICE); if (convertView == null) { clist = inflater.inflate(textviewres, null); TextView tv = (TextView) clist.findViewById(R.id.textv); tv.setText(client_list.get(position).getName()); } else { clist = convertView; } return clist; } So...

How to add condition in Android View getView (int position, View convertView, ViewGroup parent)

android,android-listview,android-arrayadapter

Do some thing like this, You can make changes, i am just adding a sample public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; if (v == null) v = inflater.inflate(R.layout.list_view_card_type, null); mTopic = (TextView) v.findViewById(R.id.topic); mItemname = (TextView) v.findViewById(R.id.name_of_item); mValue = (TextView)v.findViewById(R.id.value_of_item); String topic =...

Updating ListView On Custom ArrayAdapter

java,android,listview,android-listview,android-arrayadapter

You could use an interface and have a method in it maybe named updateListView(). Implement this interface in your FragmentActivity. In the implemented method, add code to update the listView. And in the button code of your dialog, call ((Interfacename) getActivity).updateListView()...

Parsing JSON data and populating ListView

java,android,json,listview,android-arrayadapter

Well, since you're using the default ArrayAdapter, you don't really have control over much... If you want to nicely format everything and have real control over what is displayed from your custom object (which you probably do), you need to create a custom ArrayAdapter for your Employee object and override...

In Android how to prevent updating existing items on notifyDataSetChanged()

android,android-arrayadapter

You should keep color in the data class, for example in the Message class, or keep Map in the adapter, that maps Message to Color. Then randomly create a color, when it doesn't present in the map. or use the color, if it present in the map. Using a map...

Android onItemLongClick adds position to the arrayList in different activity

android,listview,android-arrayadapter,onclicklistener,onitemlongclicklistener

I don't know if I understood the question. Anyway, have you tried to override onBackPressed? In the second activity you create a boolean variabile and inizialize it as false, then change its value when you perform a long click: mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int...

Dynamic Custom ListView?

android,listview,arraylist,android-arrayadapter

Here's how I would do it. In the main activity layout file, I'd put 2 EditText fields with ids nameEditText and ageEditText in the layout, below the listView, as well as a button to save. In your button, do not forget to add the line: android:click="onSave" and in your Main...

Dynamic Allocation of Array doesn't work for ArrayAdapter while assigning it for Spinner in Android

android,android-arrayadapter,android-spinner,dialogue

You are call calling show() before populating adapter so call addDevDialogue.show(); after spinList2.setAdapter(listAdapter2); UPDATE : Once change size of SSID String[] SSID = new String[Data.length]; Hope this will helps you....

Cursor Error in ArrayAdapter

android,android-arrayadapter,android-cursor

The problem is this line PlaylistTitle = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.PlaylistsColumns.NAME)); you have to move the cursor at the current position before accessing it. Add cursor.moveToPosition(position); before cursor.getString. Since you are dealing with a Cursor I strongly suggest that you extends a CursorAdater, or one of its concrete implementation, instead of ArrayAdapter. Performance...

[Solved]Navigation drawer selected item textColor by Custom Adapter

android,android-arrayadapter,navigation-drawer,textcolor

I had found the solution. Since i have extend the adapter. I'm just need to call and change the selected Item by position when item clicked to make changes. ListDrawer onItemClickListener: mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { selectItem(position); myadapter.setSelectedItem(position); } And...

ListView feeded with more adapters acording to need

java,android,listview,android-listview,android-arrayadapter

Is it OK to attach another adapter just when I want?            Maintaining the multiple instances of adapter for a single ListView is not a good idea.Instead of maintaining the multiple adapter instances, maintain a single instance of the adapter and update the data in the adapter using adapter.notifyDataSetChanged(); ...

ListView crashes after scrolling

android,listview,adapter,android-arrayadapter

I found the solution and I post it here, maybe it will be useful for someone else. I do not why but the combination of these 2 things solved mywind problem: 1. Use of the Picasso library to download the image 2. (I think the most important one) adding just...

NullPointerException in CustomArrayAdapter

java,android,nullpointerexception,android-arrayadapter

In your CustomAdapter.java you have to assign you inflated layout to convertView: convertView = li.inflate(layoutid,parent,false); Update: You have to set the holder to your newly inflated view: covnertView.setTag(holder); ...

Optimized way to use getView method in Adapter [duplicate]

android,android-listview,android-arrayadapter,listadapter

you should use viewholder like this: ViewHolder holder; @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub if (convertView == null) { holder = new ViewHolder(); convertView = inflater.inflate(R.layout.chocolate_list_item, parent, false); holder.txtvwChocolateName = (TextView) convertView .findViewById(R.id.xtxtvwChocolateName); holder.imgvwChocolateIcon=(ImageView)convertView.findViewById(R.id.ximgvwChocolateIcon); convertView.setTag(holder); } else { holder = (ViewHolder)...

ListView text changing but not adapter data

android,listview,adapter,android-arrayadapter

Trying to update TextView directly is not the good way. You can do it by using remove() and insert() methods to update your ArrayAdapter. For a reference, please check it here , listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if(adapter2.getItem(position).equals("Test")) { adapter2.remove("Test");...

Android Custom ArrayAdapter Listview is not clickable with Async Task

android,android-fragments,android-listview,android-asynctask,android-arrayadapter

since you are extending ListFragment, you have to override onListItemClick, and use it in place of onItemClick. Remove implements OnItemClickListener Remove lView.setOnItemClickListener(this); Delete onItemClick Then @Override public void onListItemClick(ListView l, View v, int position, long id) { Toast.makeText(getActivity(), "PLEASE WORK",Toast.LENGTH_LONG).show();k(l, v, position, id); } ...

GridView items not displaying correct images or backgrounds

android,gridview,android-arrayadapter,android-gridview

If i've understood correctly, then I think the issue is that you're processing (iterating through) all your results every time you call your getView() method, rather than the single result you want. Instead of for(SensorResult result:mSensorResultList){ String sensorType = result.getSensorType(); ... Try String sensorType = mSensorResultList.get(position).getSensorType(); ...

while populating the Listview i am getting duplicates value in listview in android

android,listview,duplicates,android-arrayadapter

I think you're only setting the data when you create the convertView. holder.tvName.setText(user.name); holder.tvHome.setText(user.hometown); should be called not be inside the if (convertView == null) block, but be always executed. So put it behind the else block....

getView in ArrayAdapter is not being called

android,android-arrayadapter

You are calling spinnerPrograms.setAdapter(adapterSchools); while adapterSchools is null. Although it looks like you are setting the variable to a new ProgramSelectionSchoolAdapter, that code is not actually called until after the background task completes. Try calling setAdapter in the done method.

Customise ArrayAdapter to fill GridView from bottom-left

java,android,gridview,android-arrayadapter

After spending most of the night on this I managed to figure out a way round it, not sure if this is the best way of doing it but it works exactly like I need it to. public class GridAdapter extends ArrayAdapter<Object> { Context context; Object[] items; int resource; int...

GridView.getItemAtPosition is always null (but list displays items)

java,android,gridview,android-arrayadapter,onitemclicklistener

the main reason is usually because your version of getItem is returning null. getItem is supposed to return the item a position in your dataset, and AdapterView.getItemAtPosition(...) calls internally adapter.getItem(position). and please get rid of this cast: ImageView image = (ImageView) (parent.getItemAtPosition(position));...

How to delete the complete view on click of delete button in android

android,android-layout,android-activity,android-listview,android-arrayadapter

I would recommend to use an ArrayList instead of a String[] in your Adapter class. It makes it a lot easier to delete or edit a View and the associated data behind it. I used this post to convert your String[] to an ArrayList, delete the item and convert back...

Reverse List Order in Array Adapter

android,android-studio,android-arrayadapter

If you want to display list in reverse order newest item on top then just reverse your list.Java collection class provide a reverse method which reverse all items in a list.See below code - Collections.reverse(aList); Above code reverse list item and store result in same list. Hope it will help...

List view setAdapter in fragment, null pointer exception

android,listview,android-fragments,android-arrayadapter

Your item variable is null in adapter = new SearchAdapter(getActivity(), R.layout.row, item);, so instanciate it before.

Android, ListView showing identical data from ArrayList?

java,android,sqlite,arraylist,android-arrayadapter

A static variable is a class attribute not an object attribute, any code referring to the variable is referring to the exact same data. In your case your overwriting the previous content of Shift attributes....

Getting Memory leak on android fragment

android,gridview,android-fragments,memory-leaks,android-arrayadapter

Without much information to go on, I think you are holding on to your fragment references. Test this by using the adb shell command dumpsys adb shell dumpsys activity <package_name> adb shell dumpsys meminfo <package_name> Navigate various fragments and run this after each time you navigate one of them. Meminfo...

Check Checkbox getting from arrayadapter

java,android,listview,checkbox,android-arrayadapter

One way is having a list of booleans in your adapter which represents the state of every checkbox. You need to init that to false and then with a setCheckbox method change the state of a specific checkbox public class CheckboxAdapter extends ArrayAdapter { Context context; List<Boolean> checkboxState; List<String> checkboxItems;...

Update the ListView after renaming a ListView item within a Popup Menu in a BaseAdapter in Android

android,listview,android-listview,android-arrayadapter,popupmenu

You Should re-populate the folderlist then call Notifydatasetchanged. fileNames = fileFunctions.listFileNames(Environment.getExternalStorageDirectory() + "/Documents/Files"); for(int i = 0; i < fileNames.length; i++){ folderList.add(new FolderBean(fileNames[i], "text")); } ...

I am trying to fetch data from database and place it in a ListView in android

android,sqlite,listview,arraylist,android-arrayadapter

try this : String strQuery="select option from (select option1 as option from table union all select option2 as option from table union all select option3 as option from table union all select option4 as option from table) as result"; Cursor c2 = db.SelectQuery(strQuery); String[] from ={"option"};//you can add as many...

Edit row in listView, ArrayAdapter - Android

android,listview,row,android-arrayadapter

You need to create your own adapter and specify the text color at the position your want: public class MyAdapter extends ArrayAdapter<String> { public MyAdapter(Context context, int resource, String[] strings) { super(context, resource, strings); } @Override public View getView(int position, View convertView, ViewGroup parent) { View view = super.getView(position, convertView,...

How to set size of colour in grid view and change it's shape to round

java,android,gridview,view,android-arrayadapter

Make your items square as explained here @Override public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, widthMeasureSpec); } And set background of your item with Drawable <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" > <solid android:color="#79bfea" /> </shape> ...

How to change the rows color in Listview on specific data from Sqlite

android,listview,android-arrayadapter

I considering the case if you are making backgroud color Green Or Red based on Fail Or not.. If you want to do this Always write else part also. if(d.getStatus().contains("0")){ view.setBackgroundColor(Color.RED); } else { view.setBackgroundColor(Color.GREEN); } ...

onListItemClick doesnt work… Why?

android,android-arrayadapter

Your OnListItemClicked() and your OnCheckChangedListener are conflicting with one another. I think you need to set the attribute android:focusable="false" on your CheckBox. You may also need to call getListView().setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS) on your ListFragment. See other SO questions for "onitemselected not working" since there are variations on this. Also I noticed that...

Android - ToggleButton losses it's state after scrolling ListView

java,android,android-listview,android-arrayadapter,android-togglebutton

You need 2 things, an array to remember which items have been toggled, and explicitly setChecked() the ones that have been toggled. private boolean[] myChecks = new boolean[myItems.length]; private class MyAdapter extends ArrayAdapter<String> { @Override public View getView(final int position, View convertView, ViewGroup parent) { ... shareToggle.setChecked(myChecks[position]); shareToggle.setOnCheckedChangeListener(new OnCheckedChangeListener() {...

Xamarin.Android: item previously inserted in ArrayAdapter is not found again

xamarin,monodroid,android-arrayadapter

I did as Matt R suggested and created a proxy that inherits from Java.Lang.Object and delegates to the actual .NET object: public class JavaObject<TValue> : Java.Lang.Object { public readonly TValue Value; internal JavaObject(TValue value) { Value = value; } public override bool Equals(Java.Lang.Object that) { if (!(that is JavaObject<TValue>)) {...

Spinner does not select item

android,android-fragments,android-studio,spinner,android-arrayadapter

Why are you finding position, when android gives you position on its own deadlineSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) { //int pos = deadlineSpinner.getSelectedItemPosition(); //why find position here? deadlineAdapter.notifyDataSetChanged(); deadlineDateText.setText(deadlineDates.get(position)); } @Override public void onNothingSelected(AdapterView<?> parentView) { } }); ...

ListView not populating from ArrayList data

android,android-listview,android-arrayadapter

Very silly mistake, see the return statement You are not returning the view on which listview was loaded. You are returning a completely new view. public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View v = inflater.inflate(R.layout.connect2,container,false); final ListView listview = (ListView)...

TextView in custom GridView adapter does not update, but ImageView does

android,arraylist,android-asynctask,android-arrayadapter,android-gridview

hmm check this out in your GridViewAudioAdapter.java public class GridViewAudioAdapter extends ArrayAdapter<AudioGridItem> { private TextView audioTitleView; // look at this madam int position; in your getView method holder = new ViewHolder(); holder.audioViewFile = (ImageView)itemView.findViewById(R.id.audio_file); holder.audioViewIcon = (ImageView)itemView.findViewById(R.id.audio_icon); audioTitleView = (TextView)itemView.findViewById(R.id.audio_title); i do not have a good explanation as now i...

List View Fragment Won't Display

android,listview,android-fragments,android-listview,android-arrayadapter

This code I don't like and not compatible with your method getMoments is: for(final MomentObject entry : getMoments()) { momentObjectAdapter.add(entry); } For now try this for a quick sample fix: List<MomentObject> myMoments = getMoments(); for(final MomentObject entry : myMoments) { The reason is getMoments() in the for loop is evaluated...

Implement OnClickListener to the ListView Items

android,mysql,listview,android-arrayadapter,onclicklistener

I would say the main reason you cannot get other information than the String name is because there is no other information than the String name in the adapter's list. So you would need to have a suitable data model and adapter that corresponds to this model. It is perfectly...

ResolveInfo getIconResource() giving really strange results (incorrect icons)

java,android,arraylist,android-arrayadapter,android-package-managers

The problem was that i was retrieving the images from the wrong place. This was the code for getting te right icons: ImageView appIcon = (ImageView)convertView.findViewById(R.id.item_app_icon); String packageName = apps.get(position).name.toString(); try { Drawable icon = getPackageManager().getApplicationIcon(packageName); appIcon.setImageDrawable(icon); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } ...

runtime error in customAdapter

java,android,listview,runtime-error,android-arrayadapter

you never assign context in your constructor. add this.context = context; to your constructor ...

How to know which of two adapters is being used in ListView onItemClick?

android,android-listview,android-arrayadapter

You can use (parent.getAdapter() instanceof CustomAdapterClass) So the onItemClick method would be @Override public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) { if (parent.getAdapter() instanceof AdapterA) { // do something with AdapterA // If AdapterA were an ArrayAdapter of custom objects then // data from those objects could...

How to update invisible/off-screen views?

java,android,android-arrayadapter,android-gridview

You got a very ugly solution there :D you should learn more about adapters and recycled views here's what you should do, // adapter class private boolean setBlueBackground = false; public View getView(int position, View convertView, ViewGroup parent) { TextView textView; if (convertView == null) { // if it's not...

Using the ArrayAdapter class

android,android-layout,android-arrayadapter

You use method 2 if the id of your text view isn't the default id. If it is, then using method 1 is perfectly fine. As a style thing I prefer to use method 2 at all times though, just to be clear about what the id is so a...

Crash when switching from hard coded string array to getStringArray()

java,android,arrays,string,android-arrayadapter

to access the Resources you need a valid Context. Move the initialization of your numbers_text, in on of the callback, eg onCreateView @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { String[] numbers_text = getResources().getStringArray(R.array.Planets); ArrayAdapter<String> adapter = new ArrayAdapter<String>( inflater.getContext(), android.R.layout.simple_list_item_1, numbers_text); setListAdapter(adapter); return super.onCreateView(inflater, container,...

Custom ArrayAdapter, listView, button

android,android-listview,android-arrayadapter

In order to have onClick of your button in YourActivity add this android:onClick line to your Button xml file. list_item.xml <Button android:onClick="onClickButtonOne" .../> Activity.java public void onClickButtonOne(View v) { // button one onclick here. int position = listview.getPositionForView(v); } ...

How to override getItem()?

android,android-arrayadapter,android-adapter

Assign the list to a class variable and access it public class FruitAdapter extends ArrayAdapter<Fruit> { private int resourceId; private List<Fruit> mObjects; public FruitAdapter(Context context, int textViewResourceId, List<Fruit> objects) { super(context, textViewResourceId, objects); resourceId = textViewResourceId; mObjects =objects; } @Override public View getView(int position, View convertView, ViewGroup parent){ Fruit fruit...

Hashmap Adapter doesn't like the Textview cast for displaying

android,hashmap,android-arrayadapter

Your HashMap is of the type <String, Card>, so you can't simply cast the returned value of getValue() to CharSequence, but you have to assign the return value of getValue() to an object of type Card and then access is properties. Supposing the Card contains a public String mValue, you...

How to get Images from Internet and past it in a ListView?

android,json,android-listview,android-arrayadapter,listadapter

Volley Library makes this work quite easy and handles all other related tasks itself. You can use ImageLoader or NetworkImageView.Follow the link for how to acheive it: https://developer.android.com/training/volley/request.html

Sorting adapter on particular array

android,listview,android-arrayadapter,baseadapter

For those looking for a solution, this is how I went about it (I don't know if its the best solution but it does work for my case). 1. Instead of populating the adapter with the individual arrays, I created an ArrayList and populated it with my arrays.I sorted it...

How to separate ImageView from adapter of ListView

android,android-listview,android-arrayadapter

I have modified the code as below and it's working fine now. Please check and let me know: public class Image { String categorias; Integer ImgCategorias; public String getCategorias() { return categorias; } public void setCategorias(String categorias) { this.categorias = categorias; } public Integer getImgCategorias() { return ImgCategorias; } public...

ArrayAdapter unable to update contents

android,android-arrayadapter

Sir; check this out private ChannelRow[] channelData; that's your instance variable, you instantiate it in your onCreate() this way channelData = new ChannelRow[]{ // default data new ChannelRow("user1", "channel1"), new ChannelRow("user2", "channel2") }; // channelData is holding is reference to the object being created with the `new` keyword so for...

Android: arrayAdapter throwing null pointer exception?

android,android-arrayadapter

Are you sure about that line ? lessonNote = (ListView)findViewById(R.id.listView1); It seems that in your layout XML, no view have "listView1" id....

Override toString() method of final BluetoothDevice class

java,android,override,android-arrayadapter,tostring

As i already mentioned in the comment you could extend the ArrayAdapter and use another method instead of the toString Method. For Example like so: public class YourAdapter extends ArrayAdapter<BluetoothDevice> { ArrayList<BluetoothDevice> devices; //other stuff @Override public View getView(int position, View convertView, ViewGroup parent) { //get view and the textView...

notifyDataSetChanged() from DialogFragment to GridView adapter in a fragment

android,android-fragments,callback,android-arrayadapter

Why you put UpdateArray() in onCreate()? mAdapter is not yet instanced. @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); UpdateArray(); } So move UpdateArray() from onCreate() to onCreateView(), after gridView.setAdapter(mAdapter); UPDATE: And also comment notifyDataSetInvalidated (), because: public void notifyDataSetInvalidated (): Notifies the attached observers that the underlying data is no...

Set value for Spinner with custom Adapter in Android

android,dynamic,android-arrayadapter,android-spinner

@Haresh Chhelana example is good, However if you want to show both name and code in spinner after selecting, check this out. List<Map<String, String>> items = new ArrayList<Map<String, String>>(); for (int i = 0; i < JA.length(); i++) { json = JA.getJSONObject(i); mapData = new HashMap<String, String>(); mapData.put("name", json.getString("Name")); mapData.put("code",...

Having a trouble with Asynchronous image loading in ListView

android,listview,parse.com,android-arrayadapter

What you are observing is i think due to the viewholder pattern of the listview.You are trying to download and set image to the images via aysnctask in getview() but when you scrollup or down the view get recycled and when you again go to that position your getview called...

Android: How to use List of String arrays inside List row

java,android,arrays,android-listview,android-arrayadapter

I suggest that you do a CustomAdapter with an ArrayList of objects instead of an array of string arrays: Public Class Concert { private String dayName; private String dayNumber; // constructors, getter and setters } So you just do: public class CustomAdapterextends BaseAdapter { Context context; protected List<Concert> listConcert; LayoutInflater...

android listview ArrayAdapter string cannot be cast to HolderView

java,android,listview,android-listview,android-arrayadapter

inflate() returns the root layout of your XML view hierarchy. Assuming the root view has the id rowbackground, this line holder.rw.setTag(menuLinkList.get(position).getId()); overwrites the viewholder tag with a String and recycling the view won't work. You can store additional data such as an id in a view holder field, no need...

onListItemClick() not working on filtered search list in an ArrayAdapter (Android)

android,search,android-listview,android-arrayadapter,textwatcher

Instead of mDataList.get(position), use mAdapter.getItem(position). The position is based on the current list contents, and mDataList is the raw unfiltered list contents.