android-adapter

Bluetooth device discovery in Android — startDiscovery()

泄露秘密 提交于 2019-11-29 23:57:39
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 startDiscovery() . Registered BLUETOOTH and BLUETOOTH_ADMIN permissions in the manifest. Things work (as

Android ListView Adapter notifyDataSetInvalidated() vs notifyDataSetChanged()

白昼怎懂夜的黑 提交于 2019-11-29 22:46: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? 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-notifydatasetchanged

Remove item from custom listview on button click

家住魔仙堡 提交于 2019-11-29 21:37:26
问题 I have a custom listview, that has 2 textviews and 2 buttons (play and delete button) I want when I click the delete button to delete the current line. My adapter class import java.util.ArrayList; import android.content.Context; import android.graphics.Color; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.Button; import

Copy to clipboard the content of a cardview

时光总嘲笑我的痴心妄想 提交于 2019-11-29 18:16:58
I've implemented a recycler card view and want to use a button click method to copy the content of cardView. There aretwo texts in cardview and i want to copy the content only, different for different cards. How can I do this? Here is my Cardview adapter. public static class ViewHolder extends RecyclerView.ViewHolder{ Button copyButton; Button shareButton; TextView title; TextView content; public ViewHolder(View itemView) { super(itemView); this.title = (TextView)itemView.findViewById(R.id.card_title); this.content = (TextView)itemView.findViewById(R.id.card_content); this.copyButton= (Button

android -BaseAdapter doesn't add new items to listView

陌路散爱 提交于 2019-11-29 17:57:10
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(jsonStr); contacts = jsonObj.getJSONArray(TAG_CONTACTS); for (int i = 0; i < contacts.length(); i++) {

Adapter update not visible rows

非 Y 不嫁゛ 提交于 2019-11-29 17:34:55
If you review this question Update adapter from different method you will see this answer https://stackoverflow.com/a/25632407/1270400 This answer works only with visible rows.But I have to add badge to not visible and visible rows.@pomber gave a tip but I can't understand it. How can I do this process ? I need an example. You shouldn't try to modify the child elements of a listview directly. Instead, modify the adapter so that you display the badge based on some condition. Then, modifying the underlying data for the adapter (and calling notifyDatasetChanged() on the adapter) and the listview

How do I access to ListView from the adapter

眉间皱痕 提交于 2019-11-29 16:08:50
问题 I have a custom ListView with my own adapter. I'm handling the click on a Button in my ListView 's item, and I want the ListView to become invisible on this click. I have no idea how to get access to the ListView from the adapter. public class ScheduleArrayAdapter extends ArrayAdapter<ScheduleListItem> { /*...*/ @Override public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; if (v == null) { LayoutInflater vi = (LayoutInflater)c.getSystemService(Context

RecyclerView.Adapter.notifyItemMoved(0,1) scrolls screen

拈花ヽ惹草 提交于 2019-11-29 10:31:40
I have a RecyclerView managed by a LinearlayoutManager, if I swap item 1 with 0 and then call mAdapter.notifyItemMoved(0,1), the moving animation causes the screen to scroll. How can I prevent it? Call scrollToPosition(0) after moving items. Unfortunately, i assume, LinearLayoutManager tries to keep first item stable, which moves so it moves the list with it. Sadly the workaround presented by yigit scrolls the RecyclerView to the top. This is the best workaround I found till now: // figure out the position of the first visible item int firstPos = manager.findFirstCompletelyVisibleItemPosition(

Use custom View in a RecyclerView Adapter?

柔情痞子 提交于 2019-11-29 09:28:47
I have a basic custom View which looks like this: public class CustomView extends RelativeLayout { private User user; private ImageView profilePicture; public CustomView(Context context) { super(context); init(); } public CustomView(Context context, AttributeSet attrs) { super(context, attrs); init(); } private void init() { inflate(getContext(), R.layout.custom_layout, this); profilePicture = (ImageView) findViewById(R.id.profilePicture); // ACCESS USER MODEL HERE // e.g. user.getUsername() } } As you can see, I'd like to access user data in the View (i.e.: user.getUsername() ). I also need

Android Data Binding : Observable List to RecyclerView's Adapter

邮差的信 提交于 2019-11-29 06:09:28
问题 Is their a way, by using the ObservableList class from the new Data Binding library and the MVVM pattern, to avoid using "notifyItem(s)..." methods from the Adapter class? Or if not what could be the simpliest way to bind an ObservableList to a RecyclerView ? Thank's for any clue ! 回答1: Have a look at following implementation of the RecyclerView 's adapter: https://github.com/radzio/android-data-binding-recyclerview/blob/master/recyclerview-binding/src/main/java/net/droidlabs/mvvm