У меня возникли проблемы с использованием OnClickListener. Я пытаюсь начать новую деятельность, когда пользователь нажимает одну из кнопок в моей кнопке с плавающим действием. Мое приложение просто падает, когда я запускаю его.Начать новую активность OnClickListener Android
В моей LaunchActivity.java:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launch);
final Button buttonNote = (Button) findViewById(R.id.note);
buttonNote.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
startActivity(new Intent(LaunchActivity.this, CreateNote.class));
}
});
}
В моей activity_launch.xml:
<com.getbase.floatingactionbutton.FloatingActionsMenu
android:id="@+id/create"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
fab:fab_addButtonColorNormal="@color/accent"
fab:fab_addButtonColorPressed="@color/accent_dark"
fab:fab_addButtonPlusIconColor="@color/window_background"
fab:fab_labelStyle="@style/menu_labels_style"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp">
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/note"
android:src="@drawable/ic_note"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingBottom="16dp"
fab:fab_title="@string/note"
fab:fab_colorNormal="@color/accent"
fab:fab_colorPressed="@color/accent_dark"/>
</com.getbase.floatingactionbutton.FloatingActionsMenu>
CreateNote.java:
public class CreateNote extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_note);
}
@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_create_note, 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);
}
}
Спасибо за любую помощь, это мой первое приложение.
Пожалуйста, разместите журналы. –
«Просто мое приложение просто падает». Это в основном помогает нам. Какая ошибка или исключение? В какой строке это происходит? Вы знаете, как читать вывод logcat? – csmckelvey
Вы заявляете свою активность в манифесте ?? – Namy