我想将列表视图添加到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
未定义
我该怎么办?
答案 0 :(得分:0)
TestFragment
等方法, SherlockListFragment
应该SherlockFragment
,而不是setListAdapter()
。