我在这里有一个新问题。我在片段中有卡片布局。其中一张卡片上有一个按钮,我打开一个新活动。
if("activity1".equals(button.getTag())){
Intent intent1 = new Intent(itemView.getContext(), MainActivity2.class);
itemView.getContext().startActivity(intent1);
}
我的MainActivity2.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
pDialog = new ProgressDialog(this);
images = new ArrayList<>();
mAdapter = new GalleryAdapter(getApplicationContext(), images);
RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(getApplicationContext(), 2);
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(mAdapter);
MainActivity2从服务器加载图像。当我单击按钮并打开MainActivity2.java时,我想要提示消息“请等待我们为您加载内容”。我尝试了下面的内容:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Toast.makeText(this, this.getIntent().getExtras().getString("value"),Toast.LENGTH_LONG).show();
但它不起作用。我该如何解决这个问题?
答案 0 :(得分:2)
什么是额外的“价值”?它来自哪里?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Toast.makeText(this, "Please wait while we load things for you", Toast.LENGTH_LONG).show();
}
答案 1 :(得分:0)
试试这个:
<强> MainActivity2.java 强>
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Toast.makeText(getApplicationContext(), "Please wait while we load things for you",Toast.LENGTH_LONG).show();
}
如何使用Toast
?见Documentation