如何在Android Activity中扩展ListActivity AppCompatActivity的位置
我想使用Activity扩展ListActivity for PullToRefresh.But我使用CustomActionBar这就是使用AppCompatActivity.How来解决这个问题的原因。谢谢你在Advanced中
public class CustomActionActivity extends ListActivity public class PullToRefreshActivity extends ListActivity { private LinkedList 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(); mListItems.addAll(Arrays.asList(mStrings)); ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, mListItems); setListAdapter(adapter); }
而不是这个:
public class CustomActionActivity extends AppCompatActivity
如果要在应用程序中使用ListView,请直接使用它而不扩展ListActivity。 喜欢这个
public class PullToRefreshActivity extends AppCompatActivity { private LinkedList 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 (); mListItems.addAll(Arrays.asList(mStrings)); ArrayAdapter adapter = new ArrayAdapter (this, android.R.layout.simple_list_item_1, mListItems); listView.setAdapter(adapter); }
根据Java doucmentation https://docs.oracle.com/javase/tutorial/java/IandI/multipleinheritance.html,我们不能inheritance多个类。 所以,如果你想要两个function,那么在你的布局中使用ListView
。
- 如何解决java.lang.string无法使用xml解析器强制转换为java.lang.integer android
- 在SD卡中移动/重命名文件
- Android:进度条将对象上传到服务器
- 如何使用Java Android SDK进行良好的实时数据流传输
- 如何在nativescript中使用本机android小部件类型定义?
- 为什么不能通过UI线程的线程访问视图?
- Android:以编程方式启用WiFi热点
- 解析数据时出错org.json.JSONException:字符0处的输入结束
- get JSONException:解析JSON响应时,无法将java.lang.String类型的值转换为JSONObject