Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Tabhost能否在扩展为实现TabListner的片段的活动中实现?_Android_Android Tabhost - Fatal编程技术网

Android Tabhost能否在扩展为实现TabListner的片段的活动中实现?

Android Tabhost能否在扩展为实现TabListner的片段的活动中实现?,android,android-tabhost,Android,Android Tabhost,我将一个活动扩展为片段并实现TabListner。我可以在该活动中实现TabHostnot片段TabHost吗。因为当我尝试时,在findViewById中找不到tabhost UserProfile.java public class UserProfile extends Fragment implements TabListener{ private static final int RESULT_OK = -1; private static int RESULT_L

我将一个活动扩展为片段并实现TabListner。我可以在该活动中实现TabHostnot片段TabHost吗。因为当我尝试时,在findViewById中找不到tabhost

UserProfile.java

public class UserProfile extends Fragment implements TabListener{


    private static final int RESULT_OK = -1;
    private static int RESULT_LOAD_IMAGE = 1;
    Map<String, AttributeValue> map = new HashMap<String, AttributeValue>();
    TabHost mTabHost;

    ImageView profilepic;
    String userId = new PassValues().getUserId();
    ArrayList<UserDetailsBean> ar = new ArrayList<UserDetailsBean>();

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.activity_user_profile,
                container, false);
        TextView name = (TextView) rootView.findViewById(R.id.name);
        //profilepic = (ImageView) rootView.findViewById(R.id.profile_pic);


        /*mTabHost = (FragmentTabHost)rootView.findViewById(R.id.tabhost);
        mTabHost.setup(getActivity(), getActivity().getSupportFragmentManager(), R.id.tabcontent1);

        mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("Tab1"),
            UserDetailsActivity.class, null);
        mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator("Tab2"),
            UserJoinedGroupsActivity.class, null);
        mTabHost.addTab(mTabHost.newTabSpec("tab3").setIndicator("Tab3"),
            UserPostedDiscussionActivity.class, null);*/






        AsyncTask<String, String, ArrayList<UserDetailsBean>> async = new GetUserDetailsDataSource()
                .execute(userId);
        try {
            ar = async.get();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ExecutionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        for (int i = 0; i < ar.size(); i++)
            name.setText(ar.get(i).getFirstname() + " "
                    + ar.get(i).getLastname());

        profilepic.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent i = new Intent(
                        Intent.ACTION_PICK,
                        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

                startActivityForResult(i, RESULT_LOAD_IMAGE);

            }
        });
        return rootView;

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK
                && null != data) {
            Uri selectedImage = data.getData();
            System.out.println(selectedImage);
            String[] filePathColumn = { MediaStore.Images.Media.DATA };
            Cursor cursor = getActivity().getContentResolver().query(
                    selectedImage, filePathColumn, null, null, null);
            cursor.moveToFirst();
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String picturePath = cursor.getString(columnIndex);
            cursor.close();
            System.out
                    .println((new PassValues().getUserId() + new LoginSharePreferences()
                            .getEmailId(getActivity())));
            System.out.println(ar.get(0).getProfilePicPath());
            AsyncTask<String, Void, Map<String, AttributeValue>> async = new InterestGroupsListDataSource(
                    userId, picturePath,
                    new LoginSharePreferences().getEmailId(getActivity()), ar
                            .get(0).getProfilePicPath(), "profile").execute();
            try {
                map = async.get();
                System.out.println(map.get("Profile Image Path").getS());
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ExecutionException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            // profilepic.setImageBitmap(BitmapFactory.decodeFile(map.get("Profile Image Path").getS()));
            profilepic.setImageBitmap(BitmapFactory.decodeFile(ar.get(0)
                    .getProfilePicPath()));

        }

    }

    @Override
    public void onTabReselected(Tab tab, android.app.FragmentTransaction ft) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onTabSelected(Tab tab, android.app.FragmentTransaction ft) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onTabUnselected(Tab tab, android.app.FragmentTransaction ft) {
        // TODO Auto-generated method stub

    }
}
activity\u user\u profile.xml

<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fadingEdgeLength="@dimen/activity_horizontal_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".UserProfile" >

    <ImageView
        android:id="@+id/profile_pic"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="43dp"
        android:minWidth="100dp"
        android:src="@drawable/button_shape_google" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/profile_pic"
        android:layout_marginTop="23dp"
        android:layout_toRightOf="@+id/profile_pic"
        android:text="Anubhav Bhardwaj"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_marginTop="180dp"
            android:layout_height="0dip"
            android:layout_weight="1">

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="-4dp"
                android:layout_weight="0" >
            </TabWidget>

        </FrameLayout>

    </LinearLayout>

    </TabHost>

</RelativeLayout>

您可以将活动扩展为TabActivity,以在程序中获得tabhost方法。如果活动扩展为FragmentActivity,则可以实现任何侦听器类,但可以在该活动中获得Tabhost

只需将你的活动更改为

    Public class *youactivity* extends TabActivity implements TabListener{
               *Your code*
}


<TabHost
android:id="@+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</TabHost>

我刚刚发布了代码。你能看到它吗?只要替换你的tabhost的id,你就可以在findviewbyid中获得tabhost。。。!不工作。使用attributes>或/>给出错误开始或结束请查看所做的更改,并提供完整的日志窗口错误以提供更多帮助