I'm new to android and saw other people having the same question but the solutions didn't work.
i tried multiple times to clean, sync and build the project after changes but every time is says that it can't resolve R
adding:
import nl.test123.R;
didn't work because than the next error popsup:Error:attribute 'nl.test123.soundboard:layout_background' not found.
also this didn't work
import android.R
this is the code:"MainActivity.java"
package nl.test123.testsoundboard;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
//import nl.test123.R;
public class MainActivity extends AppCompatActivity {
MediaPlayer mysound1;
MediaPlayer mysound2;
MediaPlayer mysound3;
private TextView mTextMessage;
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_top:
// mTextMessage.setText(R.string.title_top);
return true;
case R.id.navigation_latest:
// mTextMessage.setText(R.string.title_latest);
return true;
case R.id.navigation_favorite:
// mTextMessage.setText(R.string.title_favorite);
return true;
}
return false;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextMessage = (TextView) findViewById(R.id.message);
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
mysound1 = MediaPlayer.create(this, R.raw.bird);
mysound2 = MediaPlayer.create(this, R.raw.bomb);
mysound3 = MediaPlayer.create(this, R.raw.dog);
}
public void sound1(View view){
mysound1.start();
}
public void sound2(View view){
mysound2.start();
}
public void sound3(View view){
mysound3.start();
}
}
can anyone see what i'm doing wrong or forgetting to do.
see the xml below:"activity_main.xml"
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="nl.marvinboontjes.cucumbersoundboard.MainActivity">
<TextView
android:id="@+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="92dp"
android:layout_marginTop="128dp"
android:text="@string/title_home"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/holo_blue_light"
android:onClick="Sound1"
android:text="Bird"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="16dp"
tools:ignore="MissingConstraints" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="sound2"
android:text="Bomb"
tools:layout_editor_absoluteX="147dp"
tools:layout_editor_absoluteY="16dp"
tools:ignore="MissingConstraints" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onclick="sound3"
android:text="Dog"
tools:layout_editor_absoluteX="269dp"
tools:layout_editor_absoluteY="16dp"
tools:ignore="MissingConstraints" />
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="?android:attr/windowBackground"
app:layout_background="@color/colorPrimary"
app:itemIconTint="@drawable/nav_item_color_state"
app:itemTextColor="@drawable/nav_item_color_state"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation" />
</android.support.constraint.ConstraintLayout>