如何添加列表视图选项卡中的片段 [英] how to add listview in tab fragment

查看:114
本文介绍了如何添加列表视图选项卡中的片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了三个片段展现在我的主要活动。这是三个片段活动之一:

I created three fragments to show on my main activity. This is one of the three fragment activity :

public static class Fragment1 extends Fragment {
    /**
     * The fragment argument representing the section number for this
     * fragment.
     */
    String[] values=new String[]{"India", "java", "c++","Ad.Java", "Linux", "Unix"};
    public Fragment1() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // Create a new TextView and set its text to the fragment's section
        // number argument value.
        View v = inflater.inflate(R.layout.center, null);
        return v;
    }
}

我要显示在该片段列表视图。我试图用里面的 onCreateView这个code()方法:

ArrayAdapter<String> adapter=new ArrayAdapter<String>(Main.this,android.R.layout.simple_list_item_1,values);
        setListAdapter(adapter);

但它显示的错误。如何做到这一点?

but it shows error.. How to do this ?

推荐答案

这code虐待帮助ü..

this code ill help u..

   String[] values=new String[]{"India", "java", "c++","Ad.Java", "Linux", "Unix"};
   ListView lv;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.center, container, false);
perform(v);

    return v;
}

public void perform(View v) {
lv = (ListView)v.findViewById("your view id");
ArrayAdapter<String> adapter=new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,values);
    lv.setAdapter(adapter);

}

这篇关于如何添加列表视图选项卡中的片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆