不能在我的活动之间移动

时间:2017-09-10 15:11:53

标签: android android-activity

运行附加代码时,模拟器会崩溃。不能在我的活动之间移动。有什么问题?

Java代码:

for i, j in enumerate(range(1, len(YOUR_LIST)), start=0):
    # do your stuff
    # i == 0, j == 1 at first itteration
    print(YOUR_LIST[i], YOUR_LIST[j])

XML代码:

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);

    findViewById(R.id.btnPass).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(settings.this, WaitressRecord.class);
            startActivity(intent);
        }
    });
}

2 个答案:

答案 0 :(得分:1)

你在settings.xml文件中定义了android:onClick =“onClick”。你可以使用这个方法

 @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);
    }

        public void onClick (View v){
            Intent intent = new Intent(settings.this, WaitressRecord.class);
            startActivity(intent);
        }

答案 1 :(得分:1)

试试这个

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_home);
     Button   btnPass= (Button) findViewById(R.id.btnPass);
 }
  btnPass.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            Intent intent = new Intent(settings.this,WaitressRecord.class);
        startActivity(intent);
         }
       });

或者您可以使用Onclick方法

执行此操作
public void YourMethodName(View view) {// your onclick method 
      Intent intent = new Intent(settings.this, WaitressRecord.class);
        startActivity(intent);
}


 <Button
android:id="@+id/btnPass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="עבור"
android:onClick="YourMethodName" // mention your method name 
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
app:layout_constraintVertical_bias="0.982"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="1.0" />