Android: Spinner in fragments - android-layout

I don't know what is happening here, I am new to Android. Actually when I click on the spinner it doesn't show anything, the first value is selected by default and when I click the spinner nothing happens. I have tried it different devices and avd too still I don't know what to do. I have tried another method too (Implementing OnItemSelectedListener) but still same result. There is no error but the code doesn't seem to work and I have debugged the application too and the adapter has the 7 items but still no use.
Result Image:
When I opened the fragment the spinner with selected value and Toast:
import static android.R.layout.simple_spinner_dropdown_item;
import static android.R.layout.simple_spinner_item;
public class Attendance_fragment extends android.app.Fragment {
public Attendance_fragment() {
// Required empty public constructor
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view= inflater.inflate(R.layout.fragment_attendance_layout, container, false);
Spinner spinner;
spinner =(Spinner)view.findViewById(R.id.spinnerattendancedates);
ArrayAdapter<CharSequence> adapter=ArrayAdapter.createFromResource(getActivity(),R.array.attendance_dates, simple_spinner_item);
adapter.setDropDownViewResource(simple_spinner_dropdown_item);
adapter.setNotifyOnChange(true);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String item = parent.getItemAtPosition(position).toString();
Toast.makeText(getActivity(), "Selected " + item, Toast.LENGTH_LONG).show();
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
Toast.makeText(getActivity(), "Selected " , Toast.LENGTH_LONG).show();
}
});
return view;
}
fragment_attendance_layout.xml
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:id="#+id/spinnerattendancedates"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_gravity="bottom"
android:padding="10dp"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableLayout
android:layout_width="match_parent"
android:layout_height="440dp"
android:layout_gravity="bottom|center"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="150dp"
android:layout_height="50dp"
android:text="#string/period1"
android:id="#+id/textView"
android:layout_column="0"
android:layout_gravity="center" />
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/absentorpresent"
android:id="#+id/textView2"
android:layout_column="1"
android:layout_gravity="center_horizontal" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="150dp"
android:layout_height="50dp"
android:text="#string/period2"
android:id="#+id/textView3"
android:layout_column="0"
android:layout_gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/absentorpresent"
android:id="#+id/textView4"
android:layout_column="1"
android:layout_gravity="center_horizontal" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="150dp"
android:layout_height="50dp"
android:text="#string/period3"
android:id="#+id/textView5"
android:layout_column="0"
android:layout_gravity="center_horizontal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/absentorpresent"
android:id="#+id/textView11"
android:layout_column="1"
android:layout_gravity="center_horizontal" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="150dp"
android:layout_height="50dp"
android:text="#string/period4"
android:id="#+id/textView6"
android:layout_column="0"
android:layout_gravity="center_horizontal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/absentorpresent"
android:id="#+id/textView12"
android:layout_column="1"
android:layout_gravity="center_horizontal" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal">
<TextView
android:layout_width="150dp"
android:layout_height="50dp"
android:text="#string/period5"
android:id="#+id/textView7"
android:layout_column="0"
android:layout_gravity="center_horizontal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/absentorpresent"
android:id="#+id/textView13"
android:layout_column="1"
android:layout_gravity="center_horizontal" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="150dp"
android:layout_height="50dp"
android:text="#string/period6"
android:id="#+id/textView8"
android:layout_column="0"
android:layout_gravity="center_horizontal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/absentorpresent"
android:id="#+id/textView14"
android:layout_column="1"
android:layout_gravity="center_horizontal" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="150dp"
android:layout_height="50dp"
android:text="#string/period7"
android:id="#+id/textView9"
android:layout_column="0"
android:layout_gravity="center_horizontal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/absentorpresent"
android:id="#+id/textView15"
android:layout_column="1"
android:layout_gravity="center_horizontal" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="150dp"
android:layout_height="50dp"
android:text="#string/period8"
android:id="#+id/textView10"
android:layout_column="0"
android:layout_gravity="center_horizontal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/absentorpresent"
android:id="#+id/textView16"
android:layout_column="1"
android:layout_gravity="center_horizontal" />
</TableRow>
</TableLayout>
</ScrollView>
</RelativeLayout>
My strings.XML
<string-array name="attendance_dates">
<item>Date 1</item>
<item>Date 2</item>
<item>Date 3</item>
<item>Date 4</item>
<item>Date 5</item>
<item>Date 6</item>
<item>Date 7</item>
</string-array>

Finally corrected it. My problem was i have an "android.support.v4.widget.NestedScrollView" in Navigation Drawer Activity from where i open this Fragment. When I removed this. It worked. This is also similar for buttons which is not clickable at some circumstances.

Related

Error first time fragment is displayed with cardview

I have an error the first time that my fragment with cardviews is shown, they become much larger and only fit 2 on the screen, that is, only one row of two columns when they should show 6, first I saw that it happened and now I I realized that when re-entering the fragment since this is the one by default, if I re-enter if it is shown as it should, this fragment is inside a navigation draw
I attach a capture of how it looks at the beginning, when entering the application:
enter image description here
And in the next one it looks like this when I re-enter the fragment or I refresh it:
enter image description here
Here I leave you as seen in the android designer:
enter image description here
And finally the xml of the layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".NumericalMethods.NonlinearEquations.NonlinearEquationsFragment"
android:background="#drawable/bg_ne"
>
<TextView
android:id="#+id/title_nonlinear_ecuations"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Resolucion de \nEcuaciones No lineales "
android:textColor="#color/white"
android:textSize="30dp"
android:textAlignment="center"
android:textStyle="bold"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
/>
<GridLayout
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:rowCount="3"
android:columnCount="2"
android:layout_below="#id/title_nonlinear_ecuations">
<androidx.cardview.widget.CardView
android:id="#+id/card_fp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="0"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
>
<LinearLayout
android:layout_width="100dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_vertical|center_horizontal"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/ic_pf" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Punto Fijo"
android:textStyle="bold"
android:textAlignment="center"
android:textSize="20dp"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/car_nr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
>
<LinearLayout
android:layout_width="100dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_vertical|center_horizontal"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/ic_nr"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Newton Raphson"
android:textStyle="bold"
android:textAlignment="center"
android:textSize="20dp"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/card_sec"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="1"
android:layout_column="0"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
>
<LinearLayout
android:layout_width="100dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_vertical|center_horizontal"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/ic_sec"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="La secante"
android:textStyle="bold"
android:textAlignment="center"
android:textSize="20dp"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/car_fake_pos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="1"
android:layout_column="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
>
<LinearLayout
android:layout_width="100dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_vertical|center_horizontal"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/ic_pos_falsa"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Posicion Falsa"
android:textStyle="bold"
android:textAlignment="center"
android:textSize="20dp"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/card_bisec"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="2"
android:layout_column="0"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_vertical|center_horizontal"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_bisection"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Biseccion"
android:textStyle="bold"
android:textAlignment="center"
android:textSize="20dp"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/card_muller"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="2"
android:layout_column="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_vertical|center_horizontal"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_muller"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Muller"
android:textStyle="bold"
android:textAlignment="center"
android:textSize="20dp"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>
</GridLayout>
</RelativeLayout>
And emphasize that it only happens when the application starts, and when I take a step back, when I say this I mean the button this:
enter image description here
My Activity:
class MainActivity : AppCompatActivity() {
private lateinit var appBarConfiguration: AppBarConfiguration
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val toolbar: Toolbar = findViewById(R.id.toolbar)
setSupportActionBar(toolbar)
val fab: FloatingActionButton = findViewById(R.id.fab)
fab.setOnClickListener { view ->
Snackbar.make(view, "Aplicacion Realizada por E.R.", Snackbar.LENGTH_LONG)
.setAction("Action", null).show()
}
val drawerLayout: DrawerLayout = findViewById(R.id.drawer_layout)
val navView: NavigationView = findViewById(R.id.nav_view)
val navController = findNavController(R.id.nav_host_fragment)
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
appBarConfiguration = AppBarConfiguration(setOf(
R.id.nav_ne, R.id.nav_sne, R.id.nav_fai, R.id.nav_id, R.id.nav_edo, R.id.nav_edp), drawerLayout)
setupActionBarWithNavController(navController, appBarConfiguration)
navView.setupWithNavController(navController)
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.main, menu)
return true
}
override fun onSupportNavigateUp(): Boolean {
val navController = findNavController(R.id.nav_host_fragment)
return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp()
}
}
My mobile_navigartion.xml:
<?xml version="1.0" encoding="utf-8"?>
<navigation 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/mobile_navigation"
app:startDestination="#+id/nav_ne">
<fragment
android:id="#+id/nav_ne"
android:name="com.yr.mnlite.NumericalMethods.NonlinearEquations.NonlinearEquationsFragment"
android:label="#string/menu_ne"
tools:layout="#layout/fragment_nonlinear_equations" />
<fragment
android:id="#+id/nav_sne"
android:name="com.yr.mnlite.NumericalMethods.SistemNonlinearEquations.SistemNonlinearEquationsFragment"
android:label="#string/menu_sne"
tools:layout="#layout/fragment_sistem_nonlinear_equations" />
<fragment
android:id="#+id/nav_fai"
android:name="com.yr.mnlite.NumericalMethods.FunctionalApproximationAndInterpolation.FunctionalApproximationAndInterpolationFragment"
android:label="#string/menu_fai"
tools:layout="#layout/fragment_functional_approximation_and_interpolation" />
<fragment
android:id="#+id/nav_id"
android:name="com.yr.mnlite.NumericalMethods.IntegrationDifferentiation.IntegrationDifferentiationFragment"
android:label="#string/menu_id"
tools:layout="#layout/fragment_integration_differentiation" />
<fragment
android:id="#+id/nav_edo"
android:name="com.yr.mnlite.NumericalMethods.OrdinaryDifferentialEquations.OrdinaryDifferentialEquationsFragment"
android:label="#string/menu_edo"
tools:layout="#layout/fragment_ordinary_differential_equations" />
<fragment
android:id="#+id/nav_edp"
android:name="com.yr.mnlite.NumericalMethods.PartialDifferentialEquations.PartialDifferentialEquationsFragment"
android:label="#string/menu_edp"
tools:layout="#layout/fragment_partial_differential_equations" />
</navigation>
Thank you all very much I am new to android.
Can you try this?
<androidx.cardview.widget.CardView
android:id="#+id/card_fp"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
>

Image Button to new Activity: Android Studio

I want to link my image to a new activity, I tried multiple of codes and solution online but I am having an error.
public class MainActivity extends AppCompatActivity {
ImageButton myImageButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myImageButton = (ImageButton) findViewById(R.id.APZ);
myImageButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intentLoadActivity = new Intent(MainActivity.this,APZ.class);
startActivity(intentLoadActivity);
}
});
}
}
My problem is the ID I have set in the image is having an error, see the screenshot below:
https://imgur.com/t5KkTGl
Activity_main.XML code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Astoria Hotels and Resorts"
android:textStyle="bold"
android:textSize="25sp"
/>
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:rowCount="3"
android:columnCount="2"
>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="0"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
android:layout_marginTop="25pt"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_gravity="center_vertical|center_horizontal">
<ImageView
android:id="#+id/APZ"
android:layout_width="123dp"
android:layout_height="140dp"
app:srcCompat="#drawable/astoria_plaza___project_logo___primary_lockup__small_" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Astoria Plaza"
android:textStyle="bold"
android:textAlignment="center"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
android:layout_marginTop="25pt"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_gravity="center_vertical|center_horizontal">
<ImageView
android:id="#+id/imageView4"
android:layout_width="123dp"
android:layout_height="140dp"
app:srcCompat="#drawable/agb_transparent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Astoria Greenbelt"
android:textStyle="bold"
android:textAlignment="center"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="1"
android:layout_column="0"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_gravity="center_vertical|center_horizontal">
<ImageView
android:layout_width="123dp"
android:layout_height="140dp"
app:srcCompat="#drawable/astoria_current_transparent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Astoria Current"
android:textStyle="bold"
android:textAlignment="center"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="1"
android:layout_column="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_gravity="center_vertical|center_horizontal">
<ImageView
android:layout_width="123dp"
android:layout_height="140dp"
app:srcCompat="#drawable/ab1_transparent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Astoria Boracay"
android:textStyle="bold"
android:textAlignment="center"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="2"
android:layout_column="0"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_gravity="center_vertical|center_horizontal">
<ImageView
android:layout_width="123dp"
android:layout_height="140dp"
app:srcCompat="#drawable/abh___transparent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Astoria Bohol"
android:textStyle="bold"
android:textAlignment="center"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
</GridLayout>
</RelativeLayout>
Help please thanks!
You are using ImageButton in java. If you want to use it replace ImageView with ImageButton in your layout.xml

unable to go from one activity to another

Whenever I try to go from any activity to this particular activity,
the application goes back to the login screen.
Activity (I could not reach) Java source file:
package com.example.studentresultmaangementsystem;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TableLayout;
import android.widget.TableRow;
importandroid.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
public class Main7Activity extends AppCompatActivity {
Button button,button1;
TableLayout layout1;
TableLayout layout2;
TableRow table1row1;
TableRow table1row2;
TableRow table1row3;
TableRow table2row1;
TableRow table2row2;
TableRow table2row3;
TableRow table2row4;
TableRow table2row5;
TableRow table2row7;
TableRow table2row6;
EditText name;
EditText rollNumber;
EditText subject1;
EditText subject2;
EditText subject3;
EditText subject4;
EditText subject5;
EditText subject6;
EditText marks1,marks2,marks3,marks4,marks5,marks6;
DatabaseReference drf;
Student stu;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.adding);
layout1 = (TableLayout) findViewById(R.id.tb);
layout2 = (TableLayout)findViewById(R.id.tb2);
table1row1 = (TableRow)findViewById(R.id.r1);
table1row2 = (TableRow)findViewById(R.id.r3);
table1row3 = (TableRow)findViewById(R.id.row);
table2row1 = (TableRow)findViewById(R.id.row1);
table2row2 = (TableRow)findViewById(R.id.row2);
table2row3 = (TableRow)findViewById(R.id.row3);
table2row4 = (TableRow)findViewById(R.id.row4);
table2row5 = (TableRow)findViewById(R.id.row5);
table2row6 = (TableRow)findViewById(R.id.row6);
table2row7 = (TableRow)findViewById(R.id.row7);
button = (Button) findViewById(R.id.bu);
button1 = (Button) findViewById(R.id.bu1);
name = (EditText) findViewById(R.id.en);
rollNumber = (EditText) findViewById(R.id.er);
subject1 = (EditText) findViewById(R.id.es1);
subject2 = (EditText) findViewById(R.id.es2);
subject3 = (EditText) findViewById(R.id.es3);
subject4 = (EditText) findViewById(R.id.es4);
subject5 = (EditText) findViewById(R.id.es5);
subject6 = (EditText) findViewById(R.id.es6);
marks1 = (EditText) findViewById(R.id.em1);
marks2 = (EditText) findViewById(R.id.em2);
marks3 = (EditText) findViewById(R.id.em3);
marks4 = (EditText) findViewById(R.id.em4);
marks5 = (EditText) findViewById(R.id.em5);
marks6 = (EditText) findViewById(R.id.em6);
stu = new Student();
drf = FirebaseDatabase.getInstance().getReference().child("student");
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String n = name.getText().toString();
int rollnumber = Integer.parseInt(rollNumber.getText().toString().trim());
String s1 = subject1.getText().toString();
String s2 = subject2.getText().toString();
String s3 = subject3.getText().toString();
String s4 = subject4.getText().toString();
String s5 = subject5.getText().toString();
String s6 = subject6.getText().toString();
float m1 = Float.parseFloat(marks1.getText().toString().trim());
float m2 = Float.parseFloat(marks2.getText().toString().trim());
float m3 = Float.parseFloat(marks3.getText().toString().trim());
float m4 = Float.parseFloat(marks4.getText().toString().trim());
float m5 = Float.parseFloat(marks5.getText().toString().trim());
float m6 = Float.parseFloat(marks6.getText().toString().trim());
stu.setSubject1(s1);
stu.setSubject2(s2);
stu.setSubject3(s3);
stu.setSubject4(s4);
stu.setSubject5(s5);
stu.setSubject6(s6);
stu.setMarks1(m1);
stu.setMarks2(m2);
stu.setMarks3(m3);
stu.setMarks4(m4);
stu.setMarks5(m5);
stu.setMarks6(m6);
drf.push().setValue(stu);
Toast.makeText(Main7Activity.this, "the data has been inserted into the database", Toast.LENGTH_SHORT).show();
}
});
}
}
XML layout file tied to the above Java file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".Main7Activity"
android:background="#E0314C">
<TableLayout
android:id="#+id/tb" android:layout_width="367dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:layout_marginVertical="40dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:background="#f1f1f1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints">
<TableRow android:id="#+id/r1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#74B7D5"
android:gravity="center"
android:text="ENTER DETAILS OF STUDENT " android:textStyle="bold" />
</TableRow>
<TableRow android:id="#+id/r3">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#74B7D5"
android:gravity="center"
android:text="Name ="
android:textStyle="bold" />
<EditText android:id="#+id/en"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="5"
android:background="#ffffff"
android:gravity="center"
android:hint="enter name"
android:inputType="text"
android:maxLength="10"
android:textStyle="bold" />
</TableRow>
<TableRow android:id="#+id/row">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="1dp"
android:layout_weight="1"
android:background="#74B7D5"
android:gravity="center"
android:text="RollNo ="
android:textStyle="bold" />
<EditText
android:id="#+id/er"
android:layout_width="204dp"
android:layout_height="wrap_content"
android:layout_marginRight="1dp"
android:layout_weight="5"
android:background="#ffffff"
android:gravity="center"
android:hint="enter rollno"
android:inputType="number"
android:maxLength="6"
android:textStyle="bold" />
</TableRow>
</TableLayout>
<TableLayout
android:id="#+id/tb2"
android:layout_width="382dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:layout_marginVertical="1dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:background="#f1f1f1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tb"
tools:ignore="MissingConstraints">
<TableRow android:id="#+id/row1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#74B7D5"
android:gravity="center"
android:text="Subjects "
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="1dp"
android:layout_weight="1"
android:background="#74B7D5"
android:gravity="center"
android:text="Marks "
android:textStyle="bold" />
</TableRow>
<TableRow android:id="#+id/row2">
<EditText
android:id="#+id/es1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" ----------
android:background="#ffffff"
android:gravity="center"
android:hint="subject_name"
android:inputType="text"
android:maxLength="8"
android:textStyle="bold" />
<EditText
android:id="#+id/em1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="1dp"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="center"
android:hint="enter marks"
android:inputType="number"
android:maxLength="3"
android:textStyle="bold" />
</TableRow>
<TableRow android:id="#+id/row3">
<EditText
android:id="#+id/es2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="center"
android:hint="subject_name"
android:inputType="text"
android:maxLength="8"
android:textStyle="bold" />
<EditText
android:id="#+id/em2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="1dp"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="center"
android:hint="enter marks"
android:inputType="number"
android:maxLength="3"
android:textStyle="bold" />
</TableRow>
<TableRow android:id="#+id/row4">
<EditText
android:id="#+id/es3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="center"
android:hint="subject_name"
android:inputType="text"
android:maxLength="8"
android:textStyle="bold" />
<EditText
android:id="#+id/em3"
android:layout_width="114dp"
android:layout_height="match_parent"
android:layout_marginRight="1dp"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="center"
android:hint="enter marks"
android:inputType="number"
android:maxLength="3"
android:textStyle="bold" />
</TableRow>
<TableRow android:id="#+id/row5">
<EditText
android:id="#+id/es4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="center"
android:hint="subject_name"
android:inputType="text"
android:maxLength="8"
android:textStyle="bold" />
<EditText
android:id="#+id/em4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="1dp"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="center"
android:hint="enter marks"
android:inputType="number"
android:maxLength="3"
android:textStyle="bold" />
</TableRow>
<TableRow android:id="#+id/row6">
<EditText
android:id="#+id/es5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="center"
android:hint="subject_name"
android:inputType="text"
android:maxLength="8"
android:textStyle="bold" />
<EditText
android:id="#+id/em5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="1dp"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="center"
android:hint="enter marks"
android:inputType="number
android:maxLength="3"
android:textStyle="bold" />
</TableRow>
<TableRow android:id="#+id/row7">
<EditText
android:id="#+id/es6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="center"
android:hint="subject_name"
android:inputType="text"
android:maxLength="8"
android:textStyle="bold" />
<EditText
android:id="#+id/em6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="1dp"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="center"
android:hint="enter marks"
android:inputType="number"
android:maxLength="3"
android:textStyle="bold" />
</TableRow>
</TableLayout>
<Button
android:id="#+id/bu"
android:layout_width="106dp"
android:layout_height="39dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:onClick="addata"
android:text="Add data"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.947"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteY="631dp"
/>
<Button
android:id="#+id/bu1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:onClick="back"
android:text="Go back"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.25"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="MissingConstraints,OnClick"
tools:layout_editor_absoluteY="631dp" />
</LinearLayout>

I want to show enable a button on first click and when other button is clicked, then the previously clicked one should be inactive

I had set images in drawable and tried to set them by using onClickListeners and uing View.VISIBLE and View.GONE but once the button is clicked it becomes active forever whereas i want the previously clicked button to be disabled or inactive when new one is clicked. Please help me out anyone?
XML code:
<LinearLayout
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignBottom="#+id/toolbartitle"
android:layout_toLeftOf="#+id/toolbartitle"
android:layout_toStartOf="#+id/toolbartitle"
android:id="#+id/linearLayout3"
android:orientation="horizontal"></LinearLayout>
<HorizontalScrollView
android:layout_width="match_parent" android:layout_height="wrap_content"
android:id="#+id/horizontalScrollView"
android:fillViewport="false"
android:background="#ffffff"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:scrollbars="none"
android:scrollbarAlwaysDrawHorizontalTrack="true"
android:contextClickable="false"
android:focusable="false"
android:layout_marginTop="80dp">
<RelativeLayout
android:layout_width="match_parent" android:layout_height="wrap_content"
android:background="#ffffff"
android:layout_alignTop="#+id/horizontalScrollView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<RelativeLayout
android:layout_width="match_parent" android:layout_height="wrap_content"
android:id="#+id/miniscrollRelative"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="#string/home"
android:id="#+id/textViewab"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="50dp"
android:textSize="8dp"/>
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="#string/player"
android:id="#+id/textViewba"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="70dp"
android:layout_marginTop="50dp"
android:textSize="8dp" />
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="#string/Your_play.."
android:id="#+id/textViewca"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="130dp"
android:layout_marginTop="50dp"
android:textSize="8dp" />
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="#string/downloads"
android:id="#+id/textViewda"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="200dp"
android:layout_marginTop="50dp"
android:textSize="8dp" />
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/streaming"
android:id="#+id/textViewea"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="270dp"
android:layout_marginTop="50dp"
android:textSize="8dp" />
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtonhomea"
android:src="#drawable/homenew"
android:background="#ffffff"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:layout_alignBottom="#+id/imageButtonda"
android:layout_toRightOf="#+id/imageButtonaab"
android:layout_toEndOf="#+id/imageButtonaab" />
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtonaa"
android:src="#drawable/player"
android:layout_marginLeft="60dp"
android:background="#ffffff"
android:layout_marginTop="10dp"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtonaab"
android:src="#drawable/player_active"
android:layout_marginLeft="60dp"
android:background="#ffffff"
android:layout_marginTop="10dp"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:visibility="gone"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtonba"
android:src="#drawable/mydownload"
android:layout_marginLeft="195dp"
android:background="#ffffff"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:layout_marginTop="10dp"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtonbab"
android:src="#drawable/download_active"
android:layout_marginLeft="195dp"
android:background="#ffffff"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:layout_marginTop="10dp"
android:visibility="gone"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtonca"
android:src="#drawable/playlist"
android:layout_marginLeft="130dp"
android:background="#ffffff"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:layout_marginTop="10dp"
/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtoncab"
android:src="#drawable/playlist_active"
android:layout_marginLeft="130dp"
android:background="#ffffff"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:layout_marginTop="10dp"
android:visibility="gone"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtonda"
android:src="#drawable/streaming"
android:layout_marginLeft="265dp"
android:background="#ffffff"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:layout_marginTop="10dp"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtondab"
android:src="#drawable/streaming_active"
android:layout_marginLeft="265dp"
android:background="#ffffff"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:layout_marginTop="10dp"
android:visibility="gone"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_toRightOf="#+id/miniscrollRelative"
android:layout_marginLeft="30dp">
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/send_wishes"
android:id="#+id/textViewfa"
android:textSize="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="50dp"
/>
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/hit_parade"
android:id="#+id/textViewga"
android:textSize="8dp"
android:layout_marginLeft="78dp"
android:layout_marginTop="50dp"
/>
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/uzbek_instr"
android:id="#+id/textViewha"
android:textSize="8dp"
android:layout_marginLeft="145dp"
android:layout_marginTop="50dp"
/>
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/your_news"
android:id="#+id/textViewia"
android:textSize="8dp"
android:layout_marginLeft="220dp"
android:layout_marginTop="50dp"
/>
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/extras"
android:id="#+id/textViewja"
android:textSize="8dp"
android:layout_marginLeft="300dp"
android:layout_marginTop="50dp"
android:layout_marginRight="5dp"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtonea"
android:src="#drawable/wishes"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:background="#ffffff"
android:layout_alignTop="#+id/imageButtonfa"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtoneab"
android:src="#drawable/hitparadea"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:background="#ffffff"
android:visibility="gone"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtonfa"
android:src="#drawable/hitparade"
android:layout_marginLeft="80dp"
android:layout_marginTop="10dp"
android:background="#ffffff"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtonfab"
android:src="#drawable/hitparade1"
android:layout_marginLeft="80dp"
android:layout_marginTop="10dp"
android:background="#ffffff"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:visibility="gone"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtonga"
android:src="#drawable/instrument"
android:layout_marginLeft="150dp"
android:layout_marginTop="10dp"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:background="#ffffff"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtongab"
android:src="#drawable/instrument_active"
android:layout_marginLeft="150dp"
android:layout_marginTop="10dp"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:background="#ffffff"
android:visibility="gone"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtonha"
android:src="#drawable/news"
android:layout_marginLeft="220dp"
android:layout_marginTop="10dp"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:background="#ffffff"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtonhab"
android:src="#drawable/news_active"
android:layout_marginLeft="220dp"
android:layout_marginTop="10dp"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:background="#ffffff"
android:visibility="gone"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtonia"
android:src="#drawable/extras"
android:layout_marginLeft="290dp"
android:layout_marginTop="10dp"
android:background="#ffffff"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:layout_marginRight="5dp"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtoniab"
android:src="#drawable/extras_active"
android:layout_marginLeft="290dp"
android:layout_marginTop="10dp"
android:background="#ffffff"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:layout_marginRight="5dp"
android:visibility="gone"/>
</RelativeLayout>
</RelativeLayout>
</HorizontalScrollView>
<ImageButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/right"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignBottom="#+id/horizontalScrollView"
android:layout_alignTop="#+id/toolBar"
android:id="#+id/right" />
<ImageButton
android:id="#+id/left"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/left"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignBottom="#+id/horizontalScrollView"
android:layout_alignTop="#+id/toolBar" />
<FrameLayout
android:layout_width="match_parent" android:layout_height="match_parent"
android:name="android.app.ListFragment"
android:id="#+id/fragment"
android:background="#ffffff"
android:layout_below="#+id/horizontalScrollView"
android:layout_alignRight="#+id/toolBar"
android:layout_alignEnd="#+id/toolBar">
<FrameLayout
android:background="#f2434242"
android:layout_width="match_parent"
android:layout_height="202dp"
android:layout_gravity="left|bottom">
<RelativeLayout
android:background="#f2696868"
android:layout_width="match_parent"
android:layout_height="131dp"
android:id="#+id/relativeLayoutad"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_gravity="center_horizontal|bottom">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AD"
android:id="#+id/textView7"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="center_horizontal|top">
<ImageView
android:layout_width="49dp"
android:layout_height="49dp"
android:background="#drawable/playerbar"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/imageView3"
android:layout_alignParentTop="true"
android:layout_above="#+id/seekBar2" />
<ImageButton
android:background="#drawable/minipause"
android:layout_width="35dp"
android:layout_height="35dp"
android:id="#+id/button2"
android:layout_gravity="center_horizontal|top"
android:layout_marginRight="27dp"
android:layout_marginEnd="27dp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/button4"
android:layout_toStartOf="#+id/button4" />
<ImageButton
android:background="#drawable/minisound"
android:layout_width="35dp"
android:layout_height="35dp"
android:id="#+id/button4"
android:layout_gravity="center_horizontal|top"
android:layout_alignTop="#+id/button2"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<SeekBar
android:layout_width="match_parent"
android:layout_height="2dp"
android:id="#+id/seekBar2"
android:layout_weight="0.87"
android:progress="100"
android:progressDrawable="#drawable/seekbar3"
android:max="200"
android:thumb="#null"
android:maxHeight="3dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_below="#+id/button2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio"
android:textColor="#ffffff"
android:id="#+id/textView5"
android:layout_alignTop="#+id/imageView3"
android:layout_toRightOf="#+id/imageView3"
android:layout_toEndOf="#+id/imageView3" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="UZ"
android:textColor="#ffffff"
android:id="#+id/textView6"
android:layout_alignLeft="#+id/textView5"
android:layout_alignStart="#+id/textView5"
android:layout_alignRight="#+id/textView5"
android:layout_alignEnd="#+id/textView5"
android:layout_below="#+id/textView5" />
</RelativeLayout>
</FrameLayout>
</FrameLayout>
<TextView
android:layout_width="match_parent" android:layout_height="50dp"
android:text="player"
android:textSize="22sp"
android:gravity = "center"
android:id="#+id/toolbartitle"
android:layout_above="#+id/toolBar"
android:layout_alignLeft="#+id/toolBar"
android:layout_alignStart="#+id/toolBar" />
</RelativeLayout>
And here is the java code:
public class FragmentForScrollBar extends Fragment {
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragmentforscrollbar,null);
MyPlayer playerFragment = new MyPlayer();
fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment, playerFragment, null);
fragmentTransaction.commit();
hsv = (HorizontalScrollView) view.findViewById(R.id.horizontalScrollView);
t = (TextView)view.findViewById(R.id.toolbartitle);
home =(ImageButton)view.findViewById(R.id.imageButtonhomea);
player =(ImageButton)view.findViewById(R.id.imageButtonaa);
playlist =(ImageButton)view.findViewById(R.id.imageButtonca);
download =(ImageButton)view.findViewById(R.id.imageButtonba);
stream =(ImageButton)view.findViewById(R.id.imageButtonda);
wish =(ImageButton)view.findViewById(R.id.imageButtonea);
hit =(ImageButton)view.findViewById(R.id.imageButtonfa);
instrument =(ImageButton)view.findViewById(R.id.imageButtonga);
news1 =(ImageButton)view.findViewById(R.id.imageButtonha);
extras1 =(ImageButton)view.findViewById(R.id.imageButtonia);
homea =(ImageButton)view.findViewById(R.id.imageButtonhomea);
playera =(ImageButton)view.findViewById(R.id.imageButtonaab);
playlista =(ImageButton)view.findViewById(R.id.imageButtoncab);
downloada =(ImageButton)view.findViewById(R.id.imageButtonbab);
streama =(ImageButton)view.findViewById(R.id.imageButtondab);
wisha =(ImageButton)view.findViewById(R.id.imageButtoneab);
hita =(ImageButton)view.findViewById(R.id.imageButtonfab);
instrumenta=(ImageButton)view.findViewById(R.id.imageButtongab);
newsa =(ImageButton)view.findViewById(R.id.imageButtonhab);
extrasa =(ImageButton)view.findViewById(R.id.imageButtoniab);
miniplay= (ImageButton) view.findViewById(R.id.button2);
minisound= (ImageButton) view.findViewById(R.id.button4);
final ImageButton bP = (ImageButton) view.findViewById(R.id.left);
final ImageButton bN = (ImageButton) view.findViewById(R.id.right);
miniplay.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
if (v.getId() == R.id.minipause) {
MediaPlayer mediaPlayer= new MediaPlayer();
try {
mediaPlayer.setDataSource(url);
mediaPlayer.prepare();
} catch (Exception e) {
e.printStackTrace();
}
if (!mediaPlayer.isPlaying()) {
mediaPlayer.start();
miniplay.setImageResource(R.drawable.minipause);
} else {
mediaPlayer.pause();
miniplay.setImageResource(R.drawable.miniplay);}
}});
bP.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
bP.setVisibility(View.VISIBLE);
// bP1.setVisibility(View.GONE);
hsv.scrollTo(0, -500);
//if it's the first/last element you can bPrevoius.setEnabled(false)
}
});
bN.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
bN.setVisibility(View.VISIBLE);
// bN1.setVisibility(View.GONE);
hsv.scrollTo(500, 0);
// bN.setImageResource(R.drawable.right);
}
});
home.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
t.setText("Home");
Fragment Home = new Home();
fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment, Home);
fragmentTransaction.addToBackStack(null);
// fragmentTransaction.popBackStack();
fragmentTransaction.commit();
// t.setText("Player");
}});
player.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// player.setVisibility(View.VISIBLE);
// playera.setVisibility(View.GONE);
player.setEnabled(true);
t.setText("Player");
Fragment Myplayer = new MyPlayer();
fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment, Myplayer);
fragmentTransaction.addToBackStack(null);
// fragmentTransaction.popBackStack();
fragmentTransaction.commit();
// player.setImageResource(R.drawable.player_active);
// playera.setImageResource(R.drawable.player);
}
});
}}

how to connect two layouts in eclips

I'm beginner in Java Android developing. i have two XML file in res/layout/. named activity_fast_tip.xml and activity_setting.xml i can't connect these two component together. in activity_setting.xml
#Override
protected void onCreate (Bundle savedInstanceState)
{
super.onCreate (savedInstanceState);
setContentView(R.layout.activity_fast_tip);
tipPctTextView=(TextView)this.findViewById(R.id.tipPctTextView);
tipAmountTextView=(TextView)this.findViewById(R.id.tipAmtTextView);
totalAmountTextView=(TextView)this.findViewById(R.id.totalAmtTextView);
calcTipAmountButton=(Button)this.findViewById(R.id.calcTipButton);
billAmountTextView=(EditText)this.findViewById(R.id.billAmtEditText);
calcTipAmountButton.setOnClickListener(new onClickListener()
{
#Override
public void onClick(View v) {
calculateTip();
}
});
}
and in activity_fast_tip
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".FastTipActivity" >
<EditText
android:id="#+id/billAmtEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:ems="10"
android:gravity="right|center_vertical"
android:hint="#string/billAmount"
android:inputType="number|numberSigned|numberDecimal" >
<requestFocus />
</EditText>
<Button
android:id="#+id/calcTipButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/billAmtEditText"
android:layout_centerHorizontal="true"
android:layout_marginTop="19dp"
android:text="#string/calculateTip" />
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/billAmtEditText"
android:layout_below="#id/calcTipButton"
android:layout_marginTop="18dp"
android:text="#string/tipPercentage"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/TextView01"
android:layout_below="#+id/TextView01"
android:layout_marginLeft="0dp"
android:layout_marginTop="18dp"
android:text="#string/tipAmount"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:layout_marginTop="18dp"
android:text="#string/totalAmount"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FF0000" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/billAmtEditText"
android:layout_marginBottom="35dp"
android:text="#string/button" />
use layout inflater
http://developer.android.com/reference/android/view/LayoutInflater.html
or Include
<include
android:layout_width="fill_parent"
android:layout_height="fill_parent"
layout="#layout/activity_setting"
/>
u can use include tag a layout like this into another layout
titlebar.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width=”match_parent”
android:layout_height="wrap_content"
android:background="#color/titlebar_bg">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/gafricalogo" />
</FrameLayout>
some other layout where we include that titlebar.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:background="#color/app_bg"
android:gravity="center_horizontal">
<include layout="#layout/titlebar"/>
<TextView android:layout_width=”match_parent”
android:layout_height="wrap_content"
android:text="#string/hello"
android:padding="10dp" />
...
</LinearLayout>
http://developer.android.com/training/improving-layouts/reusing-layouts.html
2. u can use LayoutInflater
code snippet
LayoutInflater inflater = (LayoutInflater)context.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
View someView = inflater.inflate(R.layout.ur_layout,null); //2nd parameter is for viewgroup
which_layout_u_want_to_add.addView(someView);
http://developer.android.com/reference/android/view/LayoutInflater.html

Resources