【发布时间】:2015-09-22 19:28:22
【问题描述】:
我是编程和 android 开发的新手,我正在尝试在 Fragment 中实现一个按钮,该按钮将打开一个新的 Activity。
我收到错误:
无法解析方法“findViewById(int)”我也得到了 错误:无法解析构造函数 '意图(com.hashmi.omar.store.Ip6_Cab, java.lang.Class)'
下面是Ip6_Cab.java:
package com.hashmi.omar.vodafonestore;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
/**
* Created by User on 29/06/2015.
*/
public class Ip6_Cab extends Fragment implements View.OnClickListener {
Button button_ip6_24m_b2;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v =inflater.inflate(R.layout.ip6_cab,container,false);
return v;
//Sets up iphone 6 button
button_ip6_24m_b2 = (Button) findViewById(R.id.button_ip6_24m_b2);
button_ip6_24m_b2.setOnClickListener(this);
}
private void title_ip6_24m_b2_payment() {
startActivity(new Intent(Ip6_Cab.this, Ip6_24m_b2_payment.class));
}
public void onClick(View v) {
switch (v.getId()){
case R.id.button_ip6_24m_b2:
title_ip6_24m_b2_payment();
break;
}
}
}
下面是我希望打开 Activity 的按钮的 xml 布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="1dp"
android:paddingRight="1dp"
tools:context="com.hashmi.omar.store.Picker"
android:background="#ffffffff"
android:weightSum="1">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="@+id/scrollView" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="match_parent">
/Image, Bundle and Button 1
<ImageView
android:layout_width="360dp "
android:layout_height="267dp"
android:id="@+id/imageView"
android:background="@drawable/ip6_24m_b1"
android:layout_gravity="center_horizontal"
android:adjustViewBounds="true"/>
<Button
android:layout_width="54dp"
android:layout_height="28dp"
android:id="@+id/button_ip6_24m_b1"
android:background="@drawable/button_select_for_bundles"
android:layout_marginTop="5dp"
android:layout_gravity="bottom|center_horizontal" />
/Image, Bundle and Button 2
<ImageView
android:layout_width="360dp "
android:layout_height="425dp"
android:id="@+id/imageView2"
android:background="@drawable/ip6_24m_b2"
android:layout_gravity="center_horizontal"
android:adjustViewBounds="true"/>
<Button
android:layout_width="54dp"
android:layout_height="28dp"
android:id="@+id/button_ip6_24m_b2"
android:background="@drawable/button_select_for_bundles"
android:layout_marginTop="5dp"
android:layout_gravity="bottom|center_horizontal" />
</LinearLayout>
</ScrollView>
谁能帮忙?
【问题讨论】: