我有一个寻呼机适配器,它将像这样调用 ListFragment:
public Fragment getItem(int position) {
Fragment fragment = new ListViewFragment();
// set arguments here, if required
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
然后我有一个 ListActivity,我想将其更改为 ListViewFragment。
public class ImageListActivity extends ListActivity implements RadioGroup.OnCheckedChangeListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.imagelist);
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
radioGroup.setOnCheckedChangeListener(this);
setListAdapter(new ImageAdapter());
}
public void onCheckedChanged(RadioGroup group, int checkedId) {
ImageDownloader.Mode mode = ImageDownloader.Mode.NO_ASYNC_TASK;
if (checkedId == R.id.correctButton) {
mode = ImageDownloader.Mode.CORRECT;
}else if (checkedId == R.id.randomButton) {
mode = ImageDownloader.Mode.NO_DOWNLOADED_DRAWABLE;
}
((ImageAdapter) getListAdapter()).getImageDownloader().setMode(mode);
}
}
但我真的不能让它发挥作用..我试过了:
public class ListViewFragment extends ListFragment {
int mNum;
Context ctx;
View v;
static int p;
/**
* Create a new instance of CountingFragment, providing "num"
* as an argument.
*/
static ListFragment newInstance(int num) {
ListFragment f = new ListFragment();
// Supply num input as an argument.
Bundle args = new Bundle();
args.putInt("num", num);
f.setArguments(args);
return f;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
v = inflater.inflate(R.layout.imagelist, container, false);
ImageDownloader.Mode mode = ImageDownloader.Mode.NO_ASYNC_TASK;
mode = ImageDownloader.Mode.CORRECT;
((ImageAdapter) getListAdapter()).getImageDownloader().setMode(mode);
setListAdapter(new ImageAdapter());
return container;
}
}
更新: - 我只是回答我自己的问题,并制作了一个小教程来解释初学者如何通过示例将 ListAdapter 实现到您的项目中。
我从一个示例中得到了这个 ListAdapter,只需将文件复制到我的项目中,如果你运行它,就会崩溃。
因此,您需要按照我的回答进行更改并实施ListArrayAdapter
您在互联网上找到的任何内容。