我有一个ImageView.我希望在点击Imageview时从一个片段移动到另一个片段,就像我们可以从一个活动移动到另一个活动一样
Intent i=new Intent(MainActivity.this,SecondActivity.class);
startActivity(i);
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?任何人都可以一步一步向我解释吗?
我的代码如下:
mycontacts.class
public class mycontacts extends Fragment {
public mycontacts() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View v = super.getView(position, convertView, parent);
ImageView purple=(ImageView)v.findViewById(R.id.imageView1);
purple.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//how to go to tasks fragment from here???
}
});
return view;
}
}
Run Code Online (Sandbox Code Playgroud)
tasks.class
public class tasks extends Fragment {
public tasks() {
}
@Override
public View onCreateView(LayoutInflater …Run Code Online (Sandbox Code Playgroud) 我需要在 kotlin 中计算百分比,但我无法做到。请帮助我在 Kotlin 中使用正确的语法。这是我尝试过但未能得到正确答案的内容。
var percentage = (count/totalCount) * 100
it.toast("Percentage: $percentage")
Run Code Online (Sandbox Code Playgroud)
请用 kotlin 中的正确语法指导我。