Java 如何使用按钮在Android Studio的主/详细视图中从一个活动导航到另一个活动?
我目前正在使用Android Studio进行一个项目。在这个项目中,我需要使用Master/Details视图活动实现一个移动应用程序。列表中的每一项都会将用户导向特定的活动 假设第1项将用户指向名为(selln.class)的活动。此活动有一个按钮,用于将用户发送到另一个活动(BookInfo.class) 我现在面临的问题是,按钮没有响应onClick()监听器,所以当我在模拟器上运行应用程序并尝试单击按钮时,什么都没有发生 以下是我用于单击按钮的代码: 同样的问题也发生在我在显示启动屏幕几秒钟后尝试显示活动时 这是selln.xml文件Java 如何使用按钮在Android Studio的主/详细视图中从一个活动导航到另一个活动?,java,android,button,android-studio,master-detail,Java,Android,Button,Android Studio,Master Detail,我目前正在使用Android Studio进行一个项目。在这个项目中,我需要使用Master/Details视图活动实现一个移动应用程序。列表中的每一项都会将用户导向特定的活动 假设第1项将用户指向名为(selln.class)的活动。此活动有一个按钮,用于将用户发送到另一个活动(BookInfo.class) 我现在面临的问题是,按钮没有响应onClick()监听器,所以当我在模拟器上运行应用程序并尝试单击按钮时,什么都没有发生 以下是我用于单击按钮的代码: 同样的问题也发生在我在显示启动屏幕
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="@drawable/cover"
android:id="@+id/Layout">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/editText"
android:text="@string/pass_Txt_Input"
android:hint="password"
android:textColorHint="#ffffffff"
android:textColor="#ffffffff"
android:layout_below="@+id/editText2"
android:layout_alignLeft="@+id/editText2"
android:layout_alignStart="@+id/editText2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Login_Btn"
android:id="@+id/Login_Btn"
android:layout_below="@+id/editText"
android:layout_alignLeft="@+id/editText"
android:layout_alignStart="@+id/editText"
android:layout_marginLeft="50dp"
android:layout_marginTop="15dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="@+id/editText2"
android:text="@string/Email_Txt_Input"
android:hint="Username"
android:textColor="#ffffffff"
android:textColorHint="#ffffffff"
android:layout_marginTop="260dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/sign_up_btn"
android:src="@drawable/sign"
android:layout_marginTop="69dp"
android:layout_below="@+id/Login_Btn"
android:layout_alignRight="@+id/editText"
android:layout_alignEnd="@+id/editText"
android:layout_alignLeft="@+id/editText"
android:layout_alignStart="@+id/editText" />
</RelativeLayout>
我的问题是如何解决这个问题?
请帮忙。。我真的需要测试这些活动的功能:'(通过日志、toast或手动调试检查其是否正常工作,如果舒尔不正常,请将整个代码粘贴到此处。发布完整的布局和活动代码。好的。我将在此处添加代码。我也尝试了toast,但不起作用:/问题已编辑。感谢您的帮助:)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="@drawable/cover"
android:id="@+id/Layout">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/editText"
android:text="@string/pass_Txt_Input"
android:hint="password"
android:textColorHint="#ffffffff"
android:textColor="#ffffffff"
android:layout_below="@+id/editText2"
android:layout_alignLeft="@+id/editText2"
android:layout_alignStart="@+id/editText2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Login_Btn"
android:id="@+id/Login_Btn"
android:layout_below="@+id/editText"
android:layout_alignLeft="@+id/editText"
android:layout_alignStart="@+id/editText"
android:layout_marginLeft="50dp"
android:layout_marginTop="15dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="@+id/editText2"
android:text="@string/Email_Txt_Input"
android:hint="Username"
android:textColor="#ffffffff"
android:textColorHint="#ffffffff"
android:layout_marginTop="260dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/sign_up_btn"
android:src="@drawable/sign"
android:layout_marginTop="69dp"
android:layout_below="@+id/Login_Btn"
android:layout_alignRight="@+id/editText"
android:layout_alignEnd="@+id/editText"
android:layout_alignLeft="@+id/editText"
android:layout_alignStart="@+id/editText" />
</RelativeLayout>
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.Toast;
public class selln extends ActionBarActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_selln);
Button btn= (Button) findViewById(R.id.Login_Btn);
ImageButton btn1 = (ImageButton) findViewById(R.id.sign_up_btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(selln.this,BookInfo.class));
Toast.makeText(getApplicationContext(), "btn is working :/", Toast.LENGTH_LONG).show();
}
});
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(selln.this,SignUp.class));
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_book_info, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}