简体   繁体   English

从类创建意图将ListView扩展到类扩展Fragment

[英]Creating Intent from a Class extends ListView to a Class extends Fragment

I'm stuck in here for almost 2days, please help: 我在这里停留了将近2天,请帮助:

How can I create an Intent from 'MyClass extends ListView' going to a 'Test extends Fragment'? 如何从“ MyClass扩展ListView”到“测试扩展片段”创建Intent?

I used this code in MyClass: 我在MyClass中使用了以下代码:

Intent intent = new Intent(MyClass.this, Test.class); Intent intent = new Intent(MyClass.this,Test.class);

startActivity(intent); startActivity(intent);

It doesn't work. 没用 :( :(

Big help! 大帮忙! Thank you in advance! 先感谢您!

First of all you are trying to open a view from a view which that is completely wrong. 首先,您尝试从完全错误的视图中打开视图。

You have Activity class for this. 您为此具有Activity类。 Put your "MyClass" in a layout xml and set content view of your activity to that layout.(do it for both views) 将“ MyClass”放在布局xml中,然后将活动的内容视图设置为该布局。(对两个视图都进行此操作)

setContentView(R.layout.your_layout_name);

and load view by using: 并通过以下方式加载视图:

View v=(MyClass)findViewById(R.id.yourViewId); 

then use intent like: 然后使用如下意图:

Intent intent= new Intent(FirstActiviy.class,SecondActivity.class);
startActivity(intent);

but before this check Android documents. 但在此之前请检查Android文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM