Custom Listview Adapter with filter Android

You can use the Filterable interface on your Adapter, have a look at the example below: public class SearchableAdapter extends BaseAdapter implements Filterable { private List<String>originalData = null; private List<String>filteredData = null; private LayoutInflater mInflater; private ItemFilter mFilter = new ItemFilter(); public SearchableAdapter(Context context, List<String> data) { this.filteredData = data ; this.originalData = data ; … Read more

How to add a footer in ListView?

Create a footer view layout consisting of text that you want to set as footer and then try View footerView = ((LayoutInflater) ActivityContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_layout, null, false); ListView.addFooterView(footerView); Layout for footer could be something like this: <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:paddingTop=”7dip” android:paddingBottom=”7dip” android:orientation=”horizontal” android:gravity=”center”> <LinearLayout android:id=”@+id/footer_layout” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:orientation=”horizontal” android:gravity=”center” android:layout_gravity=”center”> <TextView android:text=”@string/footer_text_1″ android:id=”@+id/footer_1″ … Read more

How to fire onListItemClick in Listactivity with buttons in list?

as I wrote in previous comment solution is to setFocusable(false) on ImageButton. There is even more elegant solution try to add android:descendantFocusability=”blocksDescendants” in root layout of list element. That will make clicks onListItem possible and separately u can handle Button or ImageButton clicks Hope it helps 😉 Cheers

using notifyItemRemoved or notifyDataSetChanged with RecyclerView in Android

Use notifyItemRangeChanged(position, getItemCount()); after notifyItemRemoved(position); You don’t need to use index, just use position. See code below. private List<DetectedIssue> issues = new ArrayList<DetectedIssue>(); @Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { // – get element from your dataset at this position // – replace the contents of the view with that element if(position >0){ RiskViewHolder … Read more

List View Filter Android

Add an EditText on top of your listview in its .xml layout file. And in your activity/fragment.. lv = (ListView) findViewById(R.id.list_view); inputSearch = (EditText) findViewById(R.id.inputSearch); // Adding items to listview adapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.product_name, products); lv.setAdapter(adapter); inputSearch.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) { // When … Read more

Android: Access child views from a ListView

See: Android ListView: get data index of visible item and combine with part of Feet’s answer above, can give you something like: int wantedPosition = 10; // Whatever position you’re looking for int firstPosition = listView.getFirstVisiblePosition() – listView.getHeaderViewsCount(); // This is the same as child #0 int wantedChild = wantedPosition – firstPosition; // Say, first … Read more

Custom ListView click issue on items in Android

The issue is that Android doesn’t allow you to select list items that have elements on them that are focusable. I modified the checkbox on the list item to have an attribute like so: android:focusable=”false” Now my list items that contain checkboxes (works for buttons too) are “selectable” in the traditional sense (they light up, … Read more

How to make part of the text Bold in android at runtime?

Let’s say you have a TextView called etx. You would then use the following code: final SpannableStringBuilder sb = new SpannableStringBuilder(“HELLOO”); final StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD); // Span to make text bold final StyleSpan iss = new StyleSpan(android.graphics.Typeface.ITALIC); //Span to make text italic sb.setSpan(bss, 0, 4, Spannable.SPAN_INCLUSIVE_INCLUSIVE); // make first 4 characters Bold sb.setSpan(iss, … Read more

Android ListView not refreshing after notifyDataSetChanged

Look at your onResume method in ItemFragment: @Override public void onResume() { super.onResume(); items.clear(); items = dbHelper.getItems(); // reload the items from database adapter.notifyDataSetChanged(); } what you just have updated before calling notifyDataSetChanged() is not the adapter’s field private List<Item> items; but the identically declared field of the fragment. The adapter still stores a reference … Read more