我有一个可以显示可点击列表的片段
该列表来自方法List<Location> getAllLocations()
。
A Location
- 元素来自数据库,如下所示:
id: 1
name: Example
description: A long Description
Geo: Latitude: 46.685984999999995 Longitude: 7.867318999999998
它应该只是名称&amp;描述显示。当我点击它时,它应该在DetailView
中打开(此视图已完成且有效)。
我如何实现这样的ViewList?
片段代码
public class EditSectionFragment extends Fragment {
public EditSectionFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.edit_fragment, container,
false);
return view;
}
}
我做了什么
实现ListAdapter。添加了一大堆方法并对此感到困惑。
public class EditSectionFragment extends Fragment implements ListAdapter {
public EditSectionFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.edit_fragment, container,
false);
return view;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public int getItemViewType(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
// TODO Auto-generated method stub
return null;
}
@Override
public int getViewTypeCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isEmpty() {
// TODO Auto-generated method stub
return false;
}
@Override
public void registerDataSetObserver(DataSetObserver arg0) {
// TODO Auto-generated method stub
}
@Override
public void unregisterDataSetObserver(DataSetObserver arg0) {
// TODO Auto-generated method stub
}
@Override
public boolean areAllItemsEnabled() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isEnabled(int position) {
// TODO Auto-generated method stub
return false;
}
}
答案 0 :(得分:2)
使用ListAdapter或CursorAdapter
使用ListFragment
填充数据
您是否尝试过关注此ListView?
确保在使用ListFragment
时实施onListItemClick
- 方法