codingdir logo sitemap sitemap |
Home
PHP
C#
C++
ANDROID
JAVA
JAVASCRIPT
PYTHON

Filtering List View getting Null onTextChanged


By : , Category : android
setListAdapter(new ArrayAdapter(this,
                android.R.layout.simple_list_item_1, fv));

set it into OnCreate Method..

ReLated :

So I figured this one out. Below is a barebones example that can be used as a starting point.

import android.text.Editable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextWatcher;
import android.text.style.RelativeSizeSpan;

public class AwesomeTextWatcherDeluxe implements TextWatcher {

    private RelativeSizeSpan span;
    private SpannableString spannable;


    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        // We can use any span here. I use RelativeSizeSpan with size 1, which makes absolutely nothing.
        // Perhaps there are other spans better suited for it?
        span = new RelativeSizeSpan(1.0f);
        spannable = new SpannableString(s);
        spannable.setSpan(span, start, start + count, Spanned.SPAN_COMPOSING);
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void afterTextChanged(Editable s) {
        int beginIndex = spannable.getSpanStart(span);
        int endIndex = spannable.getSpanEnd(span);

        // Do your changes here.

        // Cleanup
        spannable.removeSpan(span);
        span = null;
        spannable = null;
    }
}

The problem is that myList.get( position ) now returns filename + " " + size. So when you do

final File temp_file = new File( file, myList.get( position ) );  

you are now referring to something else.

Solution (hacky but should work):

final File temp_file = new File( file, myList.get(position).split("\n")[0]); //updated

Update

protected void onListItemClick(ListView l, View v, int position, long id) 
{
    super.onListItemClick(l, v, position, id);
    File list[] = file.listFiles();
    final File temp_file = new File( file, list[position].getName());   

   ...
   ...

Update2

or simply:

protected void onListItemClick(ListView l, View v, int position, long id) 
    {
        super.onListItemClick(l, v, position, id);
        File list[] = file.listFiles();
        final File temp_file = list[position];   

       ...
       ...

I think I solved it. I declare my callbacks in fragments in groups like this like this

public interface $Callbacks {
        void $Callback1(String s);
        void $Callback2();
        Address $Callback2();
    }

Turns out I had multiple Callback Groups defined with the same name. I thought this is okay, because I state that explicitly with implements in my activity.

Since I changed the callback groups names to different ones I don't get the NPE anymore:

TL,DR:

I changed

implements $fragment1.callbacks $fragment2.callbacks $fragment3.callbacks

to

implements $fragment1.f1callbacks $fragment2.f2callbacks $fragment3.f3callbacks

In my activity implementing said fragment callbacks

This code (reformatted to avoid scrolling):

IList<EFModel.EntityModel.vwGetActiveEmployee> managerlist 
     = activeEmployeelist.Where(p => p.IsManager == 1)
                         .Select(p => p)
       as IList<EFModel.EntityModel.vwGetActiveEmployee>;

... will always give managerlist as a null, as Select doesn't return an IList<T> in any implementation I've ever seen. I suspect you want:

IList<vwGetActiveEmployee> managerlist =
    activeEmployeelist.Where(p => p.IsManager == 1)
                      .ToList();

Note that unless you're deliberately performing a reference type conversion which can validly fail (in which case you should usually be checking the result against null) you should prefer casts instead of as. If you'd used a cast here, you'd have seen an exception immediately, because the value returned by Select wasn't of the type you were expecting.

Comments


Message :
Login to Add Your Comments .
How to disable registered OpenCL platforms on Windows?
Is Observable broken in Angular 2 Beta 3?
Cross-thread operation not valid when using Invoke
How to pass an IEnumerable or queryable list of properties from Controller to View
Finding numbers after a certain keyword using Python
Pocketsphinx recognizes random phrases in a silence
Passing non-thread-safe objects through thread-safe containers
React scroll nav
BizTalk WCF-BasicHttp Adapter does not allow Empty string for Service Certificate Props
Why property ''cause" of Exception is repeating forever?
Privacy Policy 2017 © codingdir.com All Rights Reserved .