خرید بک لینک

Vote count: 0

I'm getting a problem. I can't update ListView when using android emulator, but on real device it works fine.

Here is a code of my ListActivity subclass.

public class FileTree extends ListActivity
{

    private File m_lst[] = null;
    private String m_path = "/";
    private ArrayAdapter<String> m_adapter = null;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_file_tree);

        m_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);

        setListAdapter(m_adapter);

        listFiles("/");
    }

    protected void onListItemClick (ListView l, View v, int position, long id)
    {
        Log.v("click", String.valueOf(position));

        position--;


        if ((position > -1) && (m_lst != null) && (position < m_lst.length))
        {
            if (m_lst[position].isDirectory())
            {
                listFiles(m_lst[position].getAbsolutePath());
            }
        } else if (position == -1)
        {
            int a = m_path.lastIndexOf('/');

            if (a > 0)
                listFiles(m_path.substring(0, a));
        }
        else
        {
            Log.v("click", "else");
        }
    }

    protected void listFiles(String path)
    {
        if (m_adapter == null)
            retu;

        Log.v("list", path);

        m_path = path;

        File f = new File(path);

        m_lst = f.listFiles();

        if (m_lst != null)
        {
            String toAdapter[] = new String[m_lst.length + 1];

            toAdapter[0] = "..";

            for (int i = 0; i < m_lst.length; i++)
            {
                if (m_lst[i].isDirectory())
                {
                    toAdapter[i + 1] = "+ " + m_lst[i].getName();
                }
                else
                {
                    toAdapter[i + 1] = m_lst[i].getName();
                }
            }

            m_adapter.clear();

            Log.v("list", "cleared");

            m_adapter.addAll(toAdapter);

            Log.v("list", "updated");

            m_adapter.notifyDataSetChanged();

            Log.v("list", "notified");
        }
    }
}

Lines after m_adapter.clear() is never executed, when I'm using an android emulator. On real device works just fine.

Seems like it stucks on synchronized (mLock) {

Here is a code of ArrayAdapter.clear()

/**
 * Remove all elements from the list.
 */
public void clear() {
    synchronized (mLock) {
        if (mOriginalValues != null) {
            mOriginalValues.clear();
        } else {
            mObjects.clear();
        }
    }
    if (mNotifyOnChange) notifyDataSetChanged();
}

What am I doing wrong?

asked 4 mins ago

- - , .

برچسب: نویسنده: استخدام کار تاريخ: يکشنبه 2 اسفند 1394 ساعت: 17:46

صفحه بندی