我想使用Activity扩展ListActivity for PullToRefresh.But我使用CustomActionBar,这就是为什么使用AppCompatActivity.How来解决这个问题。谢谢高级
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);
}
而不是:
public class CustomActionActivity extends AppCompatActivity
答案 0 :(得分:4)
如果您想在应用中使用ListView,请直接使用它而不扩展ListActivity。喜欢这个
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);
}
答案 1 :(得分:0)
根据 Java doucmentation https://docs.oracle.com/javase/tutorial/java/IandI/multipleinheritance.html,我们无法继承多个类。所以,如果你想要两个功能,那么在你的布局中使用ListView
。