android-adapter

Bluetooth device discovery in Android — startDiscovery()

守給你的承諾、 提交于 2019-11-28 20:34:45
问题 Goal: Build an Android app that discovers the names and addresses of BT devices within range and submits their values to a webservice. BT devices have not been previously bonded to the host device, I just want to poll everything as I walk about. What I've done: Pored over documentation. Implemented a local instance of the host device's BT adapter. Implemented a notification to enable BT if it isn't enabled. Registered Broadcast Receivers and Intents to parse the ACTION_FOUNDs coming off of

CursorAdapter bindView optimization

怎甘沉沦 提交于 2019-11-28 19:37:03
When overriding ArrayAdapter I know is correct using a pattern like this: if(view != null){ ...create new view setting fields from data }else return view; //reuse view is correct too using this pattern with CursorAdapters? My problem is that I have a textcolor which can be red or blue according to a cursor field, so I don't want any errors like a red color on a cell which has a field needing blue color. My bindView code is something like this: if(c.getString(2).equals("red")) textView.setTextColor(<red here>); else textView.setTextColor(<blue here>); if I reuse view can I be sure that red goes

Android ListView Adapter notifyDataSetInvalidated() vs notifyDataSetChanged()

ぐ巨炮叔叔 提交于 2019-11-28 19:26:25
问题 What is the difference? The android documentation doesn't have a description for notifyDataSetInvalidated(). I was thinking maybe you call that function to notify all registered listeners, but use notifyDataSetChanged() to not notify them? 回答1: Changed means the data set changed. Individual items updated, or items were added or removed. Invalidated means the data source is no longer available. 来源: https://stackoverflow.com/questions/6380051/android-listview-adapter-notifydatasetinvalidated-vs

How to add section separators / dividers to a ListView?

◇◆丶佛笑我妖孽 提交于 2019-11-28 17:50:35
I'm currently making a menu for my app, using a DrawerLayout and an ArrayAdapter subclass to achieve something looking like Facebook's drawer menu. I currently have no problems creating the list, but now that it looks good, i'd like to add separators between different kind of options (i.e. user-related and application-related options) and a search bar on top of the menu. The code of my current ArrayAdaptor subclass is as following : public class DrawerMenuAdapter extends ArrayAdapter<String>{ private Context context; private String[] values; private int resId; public DrawerMenuAdapter(Context

ListView or TableLayout?

*爱你&永不变心* 提交于 2019-11-28 16:33:39
I am really confused now as to which one to learn. I am an iPhone app developer and now learning Android development. I have learnt how to use a ListView with a static array of strings using an Adapter . I am used to using custom cells in iPhone, mostly for showing dynamic content like images and text in TableView s. So which is the way to go for doing that in Android? TableLayout or ListView ? As others have already said in comments, you need to clearly define what you want to do first before making a concrete decision on which type of layout to use. However, I can certainly understand the

android -BaseAdapter doesn't add new items to listView

▼魔方 西西 提交于 2019-11-28 11:48:55
问题 I don't know why my listView doesn't add new items . this is the code : ListAdapter ladap; private class GetContacts AsyncTask<Void, Void,ArrayList<HashMap<String, String>>> { @Override protected Void doInBackground(Void... arg0) { Spots_tab1_json sh = new Spots_tab1_json(); String jsonStr = sh.makeServiceCall(url + page, Spots_tab1_json.GET); ArrayList<HashMap<String, String>> dataC = new ArrayList<HashMap<String, String>>(); if (jsonStr != null) { try { JSONObject jsonObj = new JSONObject

RecyclerView Adapter notifyDataSetChanged not working

若如初见. 提交于 2019-11-28 10:42:21
I extended RecyclerView.Adapter<RecyclerView.ViewHolder> And when I called: mRecyclerView.getAdapter().notifyDataSetChanged(); Nothing happened. The only way to refresh the view is to set again the adapter ( see this answer ): mRecyclerView.setAdapter(new MyAdapter(...)); I have two issues with this solution: I can see a blink on the screen when I set again the adapter The listview returns to the first position. Any ideas? Varvara Kalinina If notifyDataSetChanged() does not trigger view updates than there is a chance that you have forgotten to call SetLayoutManager() on your RecyclerView (like

ListView updated from EditText

风格不统一 提交于 2019-11-28 10:35:55
I have a Custom Listview that it is updated from a EditText component in a dialog. I have the custom row, the adapter class and the custom dialog all working but I can't seem to trigger the code in the adatper class that would add the text from the edit text control to the list. Here is my activity code, let me know if you want the adapter code. It worked before I added the custom row and adapter to the list :( Symptom of problem: emailAdapter.notifyDataSetChanged(); does nothing public class InvitePlayers_Activity extends Activity { ListViewAdapter emailAdapter = null; ImageView imgView_mail;

The app doesn't get the localization change effect on nougat api 7 ++

社会主义新天地 提交于 2019-11-28 09:51:52
问题 I have a custom adapter for my spinner : ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item) { ............. adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); adapter.add(context.getResources().getString(R.string.value1)); adapter.add(context.getResources().getString(R.string.value2)); adapter.add(context.getResources().getString(R.string.hint)); spinner.setAdapter(adapter); Every thing work as expect but list

Android's ArrayAdapter - add strings listview instead of replace

做~自己de王妃 提交于 2019-11-28 07:10:30
问题 This is how I add an array to listview: ListView my_listview = (ListView)findViewById(R.id.listView1); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, my_array); my_listview.setAdapter(adapter); my_array is uri of a file. It works well. But next next time I want to array a new array, then I don't want to replace with with new one instead add new ones to the existing ones. How can I accomplish that? 回答1: You need to be using an ArrayList