我想向 sherlok 的 viewpageindicator 添加一个列表视图,但是当我收到错误时。我的代码是:我可以向 SherlockFragment 插入什么列表视图?
package com.example.vpiabstest;
import java.util.Date;
import java.util.List;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragment;
public class TestFragment extends SherlockFragment {
private String mContent = "???";
private static final String KEY_TAB_NUM = "key.tab.num";
public static TestFragment newInstance(String text) {
TestFragment fragment = new TestFragment();
// Supply num input as an argument.
Bundle args = new Bundle();
args.putString(KEY_TAB_NUM, text);
fragment.setArguments(args);
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_main, null);
String text = getString(R.string.tab_page_num) + mContent;
((TextView)view.findViewById(R.id.text)).setText(text);
return view;
}
**public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1, list));
}
public static final String[] list = new String[]{"France", "London", "Sweden", "Denmark", "Germany", "Finland", "Thailand", "Taiwan", "USA", "Norway", "Denmark (again)", "Lithuania", "Bosnia", "Russia", "Vietnam", "Australia"};**
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContent = getArguments() != null ? getArguments().getString(KEY_TAB_NUM) : "???";
}
}
我添加了代码行但 SetListAdapter 导致错误
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1, list));
}
但这会导致错误:
该类型的方法
setListAdapter(ArrayAdapter<String>)
未定义TestFragment
我能做些什么 ?