Android 断章取义

Android 断章取义,android,android-intent,layout,fragment,Android,Android Intent,Layout,Fragment,我有fragment应用程序。但是fragment_home.xml有一个相对的布局和imageview。我开发了代码片段,但当我单击imageview时,它没有运行意图。图像视图需要- public class HomeFragment extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedI

我有fragment应用程序。但是fragment_home.xml有一个相对的布局和imageview。我开发了代码片段,但当我单击imageview时,它没有运行意图。图像视图需要-

public class HomeFragment extends Fragment {


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

    View rootView = inflater.inflate(R.layout.fragment_home, container, false);


    return rootView;
}
我写这里是为了通过ImageView运行intents。因为我发现java不支持多个extend。像extends片段一样,活动实现。。。等等

 public class home extends Activity implements View.OnClickListener {

    ImageButton firstModule;
    ImageButton secondModule;
    ImageButton thirdModule;
    ImageButton fourModule;
    ImageButton fiveModule;
    ImageButton sx;
    ImageButton seven;

    @Override
    public void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_home);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

        //init buttons
        firstModule = (ImageButton) findViewById(R.id.imageButton1);
        secondModule = (ImageButton) findViewById(R.id.imageButton2);
        thirdModule = (ImageButton) findViewById(R.id.imageButton3);
        fourModule = (ImageButton) findViewById(R.id.imageButton4);
        fiveModule = (ImageButton) findViewById(R.id.imageButton5);
        sx = (ImageButton) findViewById(R.id.imageButto6);
        seven = (ImageButton) findViewById(R.id.imageButton7);
        firstModule.setOnClickListener(this);
        secondModule.setOnClickListener(this);
        thirdModule.setOnClickListener(this);
        fourModule.setOnClickListener(this);
        fiveModule.setOnClickListener(this);
        sx.setOnClickListener(this);
        seven.setOnClickListener(this);
    }


    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.imageButton1:
                startActivity(new Intent(home.this, MainActivitysld.class));
                break;
            case R.id.imageButton2:
                startActivity(new Intent(home.this, xxx.class));
                break;
            case R.id.imageButton3:
                startActivity(new Intent(home.this, xxx.class));
                break;
            case R.id.imageButton4:
                startActivity(new Intent(home.this, xxxx.class));
                break;
            case R.id.imageButton5:
                startActivity(new Intent(home.this, xxx.class));
                break;
            case R.id.imageButto6:
                startActivity(new Intent(home.this, xxx.class));
                break;
            case R.id.imageButton7:
                startActivity(new Intent(home.this, xxx.class));
                break;
        }

    }
编辑:我添加了fragment_home.xml

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true">

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

        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@mipmap/konu" />


        <ImageButton
            android:id="@+id/imageButton7"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@mipmap/nt" />

        <ImageButton
            android:id="@+id/imageButto6"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@mipmap/ders" />

        <ImageButton
            android:id="@+id/imageButton2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@mipmap/soru" />

        <ImageButton
            android:id="@+id/imageButton3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@mipmap/cikmis" />

        <ImageButton
            android:id="@+id/imageButton4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@mipmap/ozel" />

        <ImageButton
            android:id="@+id/imageButton5"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@mipmap/strateji" />
    </LinearLayout>
</ScrollView>

什么是家。这是什么? 您的片段活动是什么?在startActivity中,您应该给出该活动和类对象的上下文。。 如果调用了onclick方法,请交叉检查..并尝试调试。 如果不是,则设置ImageButton.setclickable(true)。
查看上述选项是否有效。

xxx
是片段或活动只需查看片段的良好教程xxx.classes名称xxx.javaClasses在java中应以大写开头。记住这一点。因此,代码更清晰。我将在何处将此代码添加到公共HomeFragment扩展片段{}或者公共主页扩展活动实现OnClickListener?home。这是出于意图。实际上我看到了。我看到了ImageView和silder菜单,我可以更改导航抽屉上的布局,但当我第一次来到布局碎片时,请不要单击ImageView。单击方法是否有效??尝试打印日志..并查看是否正在调用它。。
firstModule = (ImageButton) findViewById(R.id.imageButton1);
firstModule .setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
     startActivity(new Intent(home.this, MainActivitysld.class));
    }});

// for n numbers