片段中的意图
Intent in Fragment
我得到了片段 app.But fragment_home.xml 有一个相对布局并且有 imageviews.I 开发的代码片段,但是当我点击图像视图时,它没有运行 intents.image 视图需要-
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;
}
我在这里写 运行 意图通过 imageviews.because 我看了看 java 不支持多个 extend.like 扩展片段,Activity 实现...等等.
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>
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
什么是home.this?
你的 Fragment Activity 是什么?在 startActivity 中,你应该给出 activity 和 class 对象的上下文。
请交叉检查..并尝试调试,如果你的 onclick 方法被调用。
如果不是,设置 ImageButton.setclickable(true)。
查看以上选项是否有效。
我得到了片段 app.But fragment_home.xml 有一个相对布局并且有 imageviews.I 开发的代码片段,但是当我点击图像视图时,它没有运行 intents.image 视图需要-
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;
}
我在这里写 运行 意图通过 imageviews.because 我看了看 java 不支持多个 extend.like 扩展片段,Activity 实现...等等.
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>
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
什么是home.this? 你的 Fragment Activity 是什么?在 startActivity 中,你应该给出 activity 和 class 对象的上下文。 请交叉检查..并尝试调试,如果你的 onclick 方法被调用。 如果不是,设置 ImageButton.setclickable(true)。 查看以上选项是否有效。