How to extends ListActivity where AppCompatActivity in Android Activity
Asked Answered
P

2

11

I want to use Activity extends ListActivity for PullToRefresh.But i have use CustomActionBar that's why using AppCompatActivity.How to solve this issue.Thanks in Advanced

public class CustomActionActivity extends ListActivity

public class PullToRefreshActivity extends ListActivity {
    private LinkedList<String> mListItems;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pull_to_refresh);

        // Set a listener to be invoked when the list should be refreshed.
        ((PullToRefreshListView) getListView()).setOnRefreshListener(new PullToRefreshListView.OnRefreshListener() {
            @Override
            public void onRefresh() {
                // Do work to refresh the list here.
                new GetDataTask().execute();
            }
        });

        mListItems = new LinkedList<String>();
        mListItems.addAll(Arrays.asList(mStrings));

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

        setListAdapter(adapter);
    }

Instead of this:

public class CustomActionActivity extends AppCompatActivity
Psychro answered 17/12, 2015 at 6:44 Comment(3)
I'm sorry but I have trouble understanding the question. Can you try to clarify?Conveyancer
In my activity PullToRefresh is not working properly so that i want to use ListActivity. See i have edited my post with PullToRefreshActivity .Psychro
Consider using RecyclerView. This is newest api developer.android.com/reference/android/support/v7/widget/…Abbottson
H
8

If you want to use ListView in your app then directly use it without extending ListActivity. Like this

public class PullToRefreshActivity extends AppCompatActivity {
private LinkedList<String> mListItems;
PullToRefreshListView listView;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pull_to_refresh);
    listView = (PullToRefreshListView) findViewById(R.id.list_view); 
    // Set a listener to be invoked when the list should be refreshed.
    listView.setOnRefreshListener(new PullToRefreshListView.OnRefreshListener() {
        @Override
        public void onRefresh() {
            // Do work to refresh the list here.
            new GetDataTask().execute();
        }
    });

    mListItems = new LinkedList<String>();
    mListItems.addAll(Arrays.asList(mStrings));

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

    listView.setAdapter(adapter);
}
Holman answered 17/12, 2015 at 6:54 Comment(0)
E
0

As per the Java doucmentation https://docs.oracle.com/javase/tutorial/java/IandI/multipleinheritance.html we can't inherit multiple classes. So, if you want both the functionaloty then use ListView inside your layout.

Evanevander answered 17/12, 2015 at 6:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.