android:minSdkVersion="7"
android:targetSdkVersion="18"
我想添加操作欄到我的應用程序,但擴展到ActionBarActivity而不是ListViewActivity我無法管理onListItemClick。onListItemClick when extends ActionBarActivity
這是我的代碼。沒有錯誤,但點擊列表項不起作用。
import android.support.v7.app.ActionBarActivity;
.....
public class XXX extends ActionBarActivity {
.....
ListView getListView() {
if (mListView == null) {
mListView = (ListView) findViewById(android.R.id.list);
}
return mListView;
}
protected void setListAdapter(ListAdapter adapter) {
getListView().setAdapter(adapter);
}
protected ListAdapter getListAdapter() {
ListAdapter adapter = getListView().getAdapter();
if (adapter instanceof HeaderViewListAdapter) {
return ((HeaderViewListAdapter)adapter).getWrappedAdapter();
} else {
return adapter;
}}
protected void onListItemClick(ListView l, View v, int position, long id) {
getListView().getOnItemClickListener().onItemClick(l, v, position, id);
// TODO Auto-generated method stub
}
OK!我把它放在OnCreate上!作品! – lucignolo 2014-09-27 21:43:04