I am creating my first app with Java for android in android studio and have some problems with the LayoutInflator.
The java code of the Activity looks like this:
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.io.Serializable;
import java.util.ArrayList;
public class MatchActivity extends MatchSettingsActivity implements View.OnClickListener, Serializable {
public ArrayList<Player> matchParticipants = new ArrayList<>();
public String matchType;
public int setsAmount;
public int legsAmount;
public String checkOutType;
public String atcMode;
public int matchFinished;
public final String matchType501 = "501";
public final String matchType301 = "301";
public ArrayList<View> playerRowViewsArrayList = new ArrayList<>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_match);
ImageButton backButton = findViewById(R.id.match_back_button);
backButton.setOnClickListener(this);
Match match = (Match) getIntent().getSerializableExtra("match_object");
setMatchSettings(match.matchParticipants, match.matchType,
Integer.parseInt(match.setsAmount), Integer.parseInt(match.legsAmount),
match.checkOut, match.atcMode, match.matchFinished);
createMatchUI(matchType, matchParticipants);
}
#Override
public void onClick(View v) {
super.onClick(v);
if (v.getId() == R.id.match_back_button) {
Intent matchIntent = new Intent(MatchActivity.this, MainActivity.class);
MatchActivity.this.startActivity(matchIntent);
setContentView(R.layout.activity_main);
}
}
public void createMatchUI(String matchType, ArrayList<Player> matchParticipants) {
LinearLayout mainMatchLayout = findViewById(R.id.main_match_layout);
LayoutInflater inflater = getLayoutInflater();
if (matchType.equals(matchType501) || matchType.equals(matchType301)) {
for (int i=0; i<matchParticipants.size(); i+=1) {
View playerRowView = inflater.inflate(R.layout.player_row_layout, mainMatchLayout, false);
TextView nameTextView = playerRowView.findViewById(R.id.name);
TextView pointsTextView = playerRowView.findViewById(R.id.points);
TextView averageTextView = playerRowView.findViewById(R.id.average);
TextView lastDart1 = playerRowView.findViewById(R.id.last_d1);
TextView lastDart2 = playerRowView.findViewById(R.id.last_d2);
TextView lastDart3 = playerRowView.findViewById(R.id.last_d3);
TextView lastDartsCombined = playerRowView.findViewById(R.id.last_darts_combined);
nameTextView.setText(matchParticipants.get(i).playerName);
if (matchType.equals(matchType501)) {
pointsTextView.setText(matchType501);
} else {
pointsTextView.setText(matchType301);
}
averageTextView.setText("");
lastDart1.setText("");
lastDart2.setText("");
lastDart3.setText("");
lastDartsCombined.setText("");
playerRowViewsArrayList.add(playerRowView);
}
for (int i1=0; i1<playerRowViewsArrayList.size(); i1+=1) {
mainMatchLayout.addView(playerRowViewsArrayList.get(i1));
}
}
}
public void setMatchSettings(ArrayList<Player> matchParticipants, String matchType,
int setsAmount, int legsAmount, String checkOutType,
String atcMode, int matchFinished) {
this.matchParticipants = matchParticipants;
this.matchType = matchType;
this.setsAmount = setsAmount;
this.legsAmount = legsAmount;
this.checkOutType = checkOutType;
this.atcMode = atcMode;
this.matchFinished = matchFinished;
}
}
In the method createMatchUI I am trying to display one view for each player Object in a list.
The layout that should be created for each player using the LayoutInflator looks like this
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/points"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="30sp"
android:fontFamily="#font/suit_bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="#id/last_d1"
app:layout_constraintTop_toTopOf="parent"
android:gravity="center"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:background="#drawable/custom_rl_button_blue_borderless"/>
<TextView
android:id="#+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="16sp"
android:fontFamily="#font/suit_bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/points"
app:layout_constraintEnd_toEndOf="#id/points"
app:layout_constraintBottom_toBottomOf="#id/last_darts_combined"
android:gravity="center"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:background="#drawable/custom_rl_button_blue_borderless"/>
<TextView
android:id="#+id/last_d1"
android:layout_width="0dp"
android:layout_height="0dp"
android:textSize="16sp"
android:fontFamily="#font/suit_bold"
app:layout_constraintEnd_toStartOf="#id/last_d2"
app:layout_constraintTop_toTopOf="#id/points"
app:layout_constraintStart_toEndOf="#id/points"
app:layout_constraintBottom_toBottomOf="#id/points"
android:gravity="center"
app:layout_constraintBottom_toTopOf="#id/last_darts_combined"
android:background="#drawable/custom_rl_button_blue_borderless"/>
<TextView
android:id="#+id/last_d2"
android:layout_width="0dp"
android:layout_height="0dp"
android:textSize="16sp"
android:fontFamily="#font/suit_bold"
app:layout_constraintEnd_toStartOf="#id/last_d3"
app:layout_constraintTop_toTopOf="#id/points"
app:layout_constraintStart_toEndOf="#id/last_d1"
app:layout_constraintBottom_toBottomOf="#id/points"
android:gravity="center"
android:background="#drawable/custom_rl_button_blue_borderless"/>
<TextView
android:id="#+id/last_d3"
android:layout_width="0dp"
android:layout_height="0dp"
android:gravity="center"
android:textSize="16sp"
android:fontFamily="#font/suit_bold"
app:layout_constraintEnd_toStartOf="#id/sets"
app:layout_constraintStart_toEndOf="#id/last_d2"
app:layout_constraintTop_toTopOf="#id/points"
app:layout_constraintBottom_toBottomOf="#id/points"
android:background="#drawable/custom_rl_button_blue_borderless"/>
<TextView
android:id="#+id/last_darts_combined"
android:layout_width="0dp"
android:layout_height="0dp"
android:textSize="16sp"
android:fontFamily="#font/suit_bold"
app:layout_constraintEnd_toEndOf="#id/last_d3"
app:layout_constraintStart_toStartOf="#id/last_d1"
app:layout_constraintTop_toTopOf="#id/name"
app:layout_constraintBottom_toBottomOf="#id/name"
android:gravity="center"
android:background="#drawable/custom_rl_button_blue_borderless"/>
<TextView
android:id="#+id/sets"
android:layout_width="0dp"
android:layout_height="0dp"
android:textSize="16sp"
android:fontFamily="#font/suit_bold"
app:layout_constraintTop_toTopOf="#id/points"
app:layout_constraintEnd_toStartOf="#id/legs"
app:layout_constraintStart_toEndOf="#id/last_d3"
app:layout_constraintBottom_toBottomOf="#id/points"
android:gravity="center"
android:background="#drawable/custom_rl_button_blue_borderless"/>
<TextView
android:id="#+id/legs"
android:layout_width="0dp"
android:layout_height="0dp"
android:textSize="16sp"
android:fontFamily="#font/suit_bold"
app:layout_constraintTop_toTopOf="#id/points"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/sets"
app:layout_constraintBottom_toBottomOf="#id/points"
android:gravity="center"
android:background="#drawable/custom_rl_button_blue_borderless"/>
<TextView
android:id="#+id/average"
android:layout_width="0dp"
android:layout_height="0dp"
android:textSize="16sp"
android:fontFamily="#font/suit_bold"
app:layout_constraintStart_toEndOf="#id/last_darts_combined"
app:layout_constraintTop_toTopOf="#id/name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="#id/name"
android:gravity="center"
android:background="#drawable/custom_rl_button_blue_borderless"/>
<View
android:id="#+id/divider"
android:layout_width="1dp"
android:layout_height="0dp"
android:background="?android:attr/listDivider"
app:layout_constraintBottom_toBottomOf="#+id/name"
app:layout_constraintTop_toTopOf="#+id/points"
app:layout_constraintEnd_toStartOf="#id/points"
app:layout_constraintStart_toStartOf="#id/points"/>
<View
android:id="#+id/divider2"
android:layout_width="1dp"
android:layout_height="0dp"
android:background="?android:attr/listDivider"
app:layout_constraintBottom_toBottomOf="#+id/name"
app:layout_constraintTop_toTopOf="#+id/points"
app:layout_constraintEnd_toStartOf="#id/last_d1"
app:layout_constraintStart_toEndOf="#id/points"/>
<View
android:id="#+id/divider3"
android:layout_width="1dp"
android:layout_height="0dp"
android:background="?android:attr/listDivider"
app:layout_constraintBottom_toBottomOf="#+id/points"
app:layout_constraintTop_toTopOf="#+id/points"
app:layout_constraintEnd_toStartOf="#id/last_d2"
app:layout_constraintStart_toEndOf="#id/last_d1"/>
<View
android:id="#+id/divider4"
android:layout_width="1dp"
android:layout_height="0dp"
android:background="?android:attr/listDivider"
app:layout_constraintBottom_toBottomOf="#+id/points"
app:layout_constraintTop_toTopOf="#+id/points"
app:layout_constraintEnd_toStartOf="#id/last_d3"
app:layout_constraintStart_toEndOf="#id/last_d2"/>
<View
android:id="#+id/divider5"
android:layout_width="1dp"
android:layout_height="0dp"
android:background="?android:attr/listDivider"
app:layout_constraintBottom_toBottomOf="#+id/name"
app:layout_constraintTop_toTopOf="#+id/points"
app:layout_constraintEnd_toStartOf="#id/sets"
app:layout_constraintStart_toEndOf="#id/last_d3"/>
<View
android:id="#+id/divider6"
android:layout_width="1dp"
android:layout_height="0dp"
android:background="?android:attr/listDivider"
app:layout_constraintBottom_toBottomOf="#+id/points"
app:layout_constraintTop_toTopOf="#+id/points"
app:layout_constraintEnd_toStartOf="#id/legs"
app:layout_constraintStart_toEndOf="#id/sets"/>
<View
android:id="#+id/divider7"
android:layout_width="1dp"
android:layout_height="0dp"
android:background="?android:attr/listDivider"
app:layout_constraintBottom_toBottomOf="#+id/name"
app:layout_constraintTop_toTopOf="#+id/points"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/legs"/>
<View
android:id="#+id/divider8"
android:layout_width="0dp"
android:layout_height="1dp"
android:background="?android:attr/listDivider"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="#id/points"
app:layout_constraintTop_toBottomOf="#id/points"/>
<View
android:id="#+id/divider9"
android:layout_width="0dp"
android:layout_height="1dp"
android:background="?android:attr/listDivider"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="#id/points"
app:layout_constraintTop_toTopOf="#id/points"/>
<View
android:id="#+id/divider10"
android:layout_width="0dp"
android:layout_height="1dp"
android:background="?android:attr/listDivider"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="#id/name"
app:layout_constraintTop_toBottomOf="#id/name"/>
</androidx.constraintlayout.widget.ConstraintLayout>
and the root activity/layout looks like this:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background_color">
<androidx.appcompat.widget.Toolbar
android:id="#+id/match_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/toolbar_color"
android:theme="#style/toolbarTheme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</androidx.appcompat.widget.Toolbar>
<TextView
android:id="#+id/match_label"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:gravity="center_vertical"
app:layout_constraintStart_toStartOf="#id/match_toolbar"
app:layout_constraintBottom_toBottomOf="#id/match_toolbar"
app:layout_constraintEnd_toEndOf="#id/match_toolbar"
app:layout_constraintTop_toTopOf="#id/match_toolbar"
android:text="#string/match_label"
android:textColor="#color/white"
android:fontFamily="#font/suit_light"
android:textSize="20sp"/>
<ImageButton
android:id="#+id/match_back_button"
android:layout_width="35dp"
android:layout_height="25dp"
android:background="#drawable/back_arrow2"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
app:layout_constraintBottom_toBottomOf="#id/match_toolbar"
app:layout_constraintStart_toStartOf="#id/match_toolbar"
app:layout_constraintTop_toTopOf="#id/match_toolbar" />
<LinearLayout
android:id="#+id/main_match_layout"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="horizontal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/match_toolbar"
app:layout_constraintBottom_toTopOf="#id/input_layout"
android:layout_margin="15dp">
</LinearLayout>
<LinearLayout
android:id="#+id/input_layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
[...]
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
The problem I am facing is, that always only one view is added to the root layout (mainMatchLayout) like this:
Instead I want one layout for each player object that exists in my ArrayList matchParticipants.
Can anyone figure out what I'm doing wrong?
Thank you.
Related
I'm building an app using Constraint layout, but it has extra space bottom and top. I can't find where they come from. I checked maybe ten times from top to bottom all code but there is no margin or padding or anything else for it.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/black"
android:paddingLeft="0dp"
android:paddingTop="0dp"
android:paddingRight="0dp"
android:paddingBottom="0dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/Brand"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="#id/guideline"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/brandname"
style="#style/viewParent.headerText"
android:text="Did"
android:textColor="#color/white" />
<TextView
android:id="#+id/brandname2"
style="#style/viewParent.headerText2"
android:layout_toRightOf="#id/brandname"
android:text="You"
android:textColor="#color/yellow" />
<TextView
style="#style/viewParent.headerText2"
android:layout_toRightOf="#id/brandname2"
android:text="Know!"
android:textColor="#color/red"
android:textStyle="bold|italic" />
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/container_main"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="4dp"
android:background="#drawable/card_bg"
android:paddingLeft="16dp"
android:paddingRight="16dp"
app:layout_constraintBottom_toTopOf="#id/guideline2"
app:layout_constraintEnd_toEndOf="#id/guidelineyazisag"
app:layout_constraintStart_toStartOf="#id/guidelineyazisol"
app:layout_constraintTop_toBottomOf="#id/guideline">
<TextView
android:id="#+id/activity_main_text_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="simple Title Text"
android:textColor="#5E4C4C"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/activity_main_did_u_know"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Category"
android:textColor="#5E4C4C"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.core.widget.NestedScrollView
android:id="#+id/scrollview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:fillViewport="true"
app:layout_constraintBottom_toTopOf="#id/activity_main_image_view"
app:layout_constraintTop_toBottomOf="#id/activity_main_did_u_know">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#id/activity_main_image_view"
app:layout_constraintTop_toBottomOf="#id/activity_main_did_u_know">
<TextView
android:id="#+id/factTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:gravity="center_vertical|center_horizontal"
android:lineSpacingExtra="8dp"
android:padding="10dp"
android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged."
android:textColor="#000000"
android:textSize="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
<ImageView
android:id="#+id/activity_main_image_view"
android:layout_width="30dp"
android:layout_height="40dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:clickable="true"
android:src="#drawable/ic_share_black_24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/scrollview" />
<ImageView
android:id="#+id/activity_main_fav_button"
android:layout_width="30dp"
android:layout_height="40dp"
android:layout_margin="16dp"
android:clickable="true"
android:src="#drawable/ic_favorite_border_black_24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/scrollview" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/LeftRight"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="#id/adView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/guideline2">
<ImageView
android:id="#+id/activity_main_left_button"
android:layout_width="60dp"
android:layout_height="60dp"
android:clickable="true"
android:src="#drawable/ic_previous"
android:elevation="3dp"
android:background="#drawable/okarka"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#id/guideline3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/activity_main_right_button"
android:layout_width="60dp"
android:layout_height="60dp"
android:clickable="true"
android:src="#drawable/ic_next"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
android:background="#drawable/okarka"
app:layout_constraintStart_toEndOf="#+id/guideline3"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.5" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
ads:layout_constraintBottom_toBottomOf="parent"
ads:layout_constraintLeft_toLeftOf="parent"
ads:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/LeftRight" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.076" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.7" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guidelineyazisol"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.07" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guidelineyazisag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.93" />
</androidx.constraintlayout.widget.ConstraintLayout>
I tried adding guidelines to 0 points in the bottom but it also starts in that space. I gave -(minus) values to margin and padding but doesn't work. I don't know what else to do. You can see from screenshots how it looks.
public class MainActivity extends AppCompatActivity {
private ColorWheel colorWheel = new ColorWheel();
private TextView factTextView;
private TextView textViewId;
private TextView textViewTableName;
ImageView tableImageView;
AdView adView;
ImageView shareImageView;
ImageView favImageView;
float x1,x2,y1,y2;
int i = 1;
int adCounter = 0;
private ConstraintLayout constraintLayout;
String fact;
ArrayList<Fact> favList = new ArrayList<>();
private InterstitialAd mInterstitial;
AdRequest interAdRequest;
int favId;
String favTable;
Typeface typeface;
List<Fact> mData;
private DatabaseFacts db;
GradientDrawable shape;
#SuppressLint({"ClickableViewAccessibility", "SetTextI18n"})
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db = new DatabaseFacts(this);
db.copyDbIfNotExists();
shape = new GradientDrawable();
shape.setCornerRadius(40);
mData = new ArrayList<>();
MobileAds.initialize(this, "ca-app-pub-2469721886989416~7390658870");
adView = findViewById(R.id.adView);
AdRequest bannerAdRequest = new AdRequest.Builder().build();
adView.loadAd(bannerAdRequest);
interAdRequest = new AdRequest.Builder().build();
mInterstitial = new InterstitialAd(this);
mInterstitial.setAdUnitId("ca-app-pub-2469721886989416/9441000894");
mInterstitial.loadAd(interAdRequest);
factTextView = findViewById(R.id.factTextView);
constraintLayout = (ConstraintLayout) findViewById(R.id.container_main);
textViewId = findViewById(R.id.activity_main_text_view_id);
favImageView = findViewById(R.id.activity_main_fav_button);
shareImageView = findViewById(R.id.activity_main_image_view);
textViewTableName = findViewById(R.id.activity_main_did_u_know);
// tableImageView = findViewById(R.id.img_user);
// if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
// typeface = getResources().getFont(R.font.sourceserifproregular);
// }
factTextView.setTypeface(typeface);
Intent intent = getIntent();
final int choice = intent.getIntExtra("choice",0);
switch (choice) {
case 1:
textViewTableName.setText("General Facts");
factTextView.setText(db.getFact((readFromShared("defaultKey") - 1), DatabaseFacts.TABLE_GENERAL_NAME).getFact());
textViewId.setText("Fact " + (readFromShared("defaultKey") - 1) + " of " + db.getFactsCount(DatabaseFacts.TABLE_GENERAL_NAME));
if (db.getFact((readFromShared("defaultKey") - 1), DatabaseFacts.TABLE_GENERAL_NAME).isFavorite() == 0) {
favImageView.setImageResource(R.drawable.ic_favorite_border_black_24dp);
} else {
favImageView.setImageResource(R.drawable.ic_favorite_black_24dp);
}
ImageView leftClick = (ImageView) findViewById(R.id.activity_main_left_button);
leftClick.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
leftClickMethod("defaultKey", DatabaseFacts.TABLE_GENERAL_NAME);
}
});
ImageView rightClick = (ImageView) findViewById(R.id.activity_main_right_button);
rightClick.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
rightClickMethod("defaultKey",DatabaseFacts.TABLE_GENERAL_NAME);
return;
}
});
favImageView.setOnClickListener(v -> handleFavorites("defaultKey", DatabaseFacts.TABLE_GENERAL_NAME));
break;
Remove app:layout_constraintBottom_toTopOf="#id/guideline" from Brand and app:layout_constraintTop_toBottomOf="#id/LeftRight" from adView. You can't put constraints for Top and Bottom because it will center your View between those two constraints. Same about left and right (start, end), but you have match_parent here, so this problem doesn't occur (visualy - if you set wrap_content, view will go to the center too).
Hello friends i am creating a mp3 player which have two activities how can i control media from both activities like play pause and progress bar here is
the first activity have list of the song when user click any songs it work fine and below this song listview i create progress and bar and media controll button like play pause and next and back its include spreate layoute ad in below list when user click on this layout it redirect another activity and which have also same feature like play pause and and progress bar how can i controll this media from both activities?
my 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:background="#1e1e2c"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/song_list"/>
<include
android:layout_below="#+id/song_title"
layout="#layout/mediacontroller"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<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:background="#1e1e2c"
android:layout_height="match_parent">
<ImageView
android:layout_width="180dp"
android:layout_height="180dp"
android:id="#+id/rotate"
android:layout_centerInParent="true"
android:src="#drawable/musiccirlce"/>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true">
<ImageButton
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:clickable="true"
android:focusable="true"
android:id="#+id/repeat"
android:visibility="visible"
android:scaleType="centerCrop"
android:background="?attr/selectableItemBackgroundBorderless"
android:src="#drawable/baseline_repeat_white_48dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.023"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.811" />
<ImageButton
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:clickable="true"
android:focusable="true"
android:id="#+id/repeatenable"
android:visibility="gone"
android:scaleType="centerCrop"
android:background="?attr/selectableItemBackgroundBorderless"
android:src="#drawable/repeatenable"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.023"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.811" />
<ImageButton
android:id="#+id/shuffle"
android:layout_width="20dp"
android:layout_height="24dp"
android:visibility="visible"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:scaleType="centerCrop"
android:src="#drawable/baseline_shuffle_white_48dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.976"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.811" />
<ImageButton
android:layout_width="25dp"
android:id="#+id/shufflenable"
android:layout_height="25dp"
android:visibility="gone"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:scaleType="centerCrop"
android:background="?attr/selectableItemBackgroundBorderless"
android:src="#drawable/shuffulenabled"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.976"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.811" />
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="99dp"
android:layout_alignParentBottom="true">
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="80dp"
android:clickable="false"
android:background="#color/backgroundColor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:id="#+id/imageButton2"
android:layout_width="55dp"
android:layout_height="55dp"
android:padding="15dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="16dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackgroundBorderless"
android:scaleType="centerCrop"
android:src="#mipmap/outline_thumb_up_alt_black_48"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/songtime"
app:layout_constraintVertical_bias="0.56"
android:layout_marginRight="8dp"
android:layout_marginLeft="16dp" />
<ImageButton
android:id="#+id/imageButton2new"
android:layout_width="55dp"
android:layout_height="55dp"
android:padding="15dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="16dp"
android:visibility="gone"
android:clickable="true"
android:focusable="true"
android:scaleType="centerCrop"
android:background="?attr/selectableItemBackgroundBorderless"
android:src="#mipmap/baseline_thumb_up_alt_black_48"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/songtime"
app:layout_constraintVertical_bias="0.56"
android:layout_marginRight="8dp"
android:layout_marginLeft="16dp" />
<ImageButton
android:id="#+id/button"
android:layout_width="55dp"
android:layout_height="55dp"
android:padding="15dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="8dp"
android:scaleType="centerCrop"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackgroundBorderless"
android:src="#mipmap/baseline_thumb_down_alt_black_18"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/endTime"
app:layout_constraintVertical_bias="0.56"
android:layout_marginRight="16dp"
android:layout_marginLeft="8dp" />
<ImageButton
android:id="#+id/buttontwo"
android:layout_width="55dp"
android:layout_height="55dp"
android:padding="15dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="8dp"
android:visibility="gone"
android:scaleType="centerCrop"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackgroundBorderless"
android:src="#mipmap/baseline_thumb_down_alt_black_18"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/endTime"
app:layout_constraintVertical_bias="0.56"
android:layout_marginRight="16dp"
android:layout_marginLeft="8dp" />
<TextView
android:id="#+id/songtime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:fontFamily="sans-serif"
android:text="1:05"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="#+id/endTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:fontFamily="sans-serif"
android:text="3:06"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<LinearLayout
android:id="#+id/linearLayout5"
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0">
<ImageButton
android:id="#+id/play_button_main"
android:layout_width="55dp"
android:layout_height="55dp"
android:scaleType="centerCrop"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackgroundBorderless"
android:src="#drawable/play_button" />
<ImageButton
android:id="#+id/pause_button_main"
android:layout_width="55dp"
android:visibility="gone"
android:scaleType="centerCrop"
android:layout_height="55dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackgroundBorderless"
android:src="#drawable/pause_button" />
</LinearLayout>
<ImageButton
android:layout_width="55dp"
android:id="#+id/pervious"
android:layout_height="55dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="15dp"
android:clickable="true"
android:focusable="true"
android:scaleType="fitCenter"
android:src="#drawable/backword_button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/linearLayout5"
app:layout_constraintHorizontal_bias="0.754"
app:layout_constraintStart_toEndOf="#+id/imageButton2"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
<ImageButton
android:id="#+id/next"
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="15dp"
android:scaleType="fitCenter"
android:src="#drawable/forword_button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/button"
app:layout_constraintHorizontal_bias="0.25"
app:layout_constraintStart_toEndOf="#+id/linearLayout5"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
/>
</android.support.constraint.ConstraintLayout>
</RelativeLayout>
<SeekBar
android:id="#+id/seekBar3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="#+id/relativeLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/relativeLayout"
app:layout_constraintVertical_bias="0.75" />
</android.support.constraint.ConstraintLayout>
</RelativeLayout>
package music.player.musicplayer;
import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
public class MainActivity extends AppCompatActivity {
private ArrayList<Song> songList;
private ListView songView;
LinearLayout nextactivity;
SeekBar seekBar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
songView = findViewById(R.id.song_list);
songList = new ArrayList<Song>();
seekBar=findViewById(R.id.seekBar2);
getSongList();
Collections.sort(songList, new Comparator<Song>(){
public int compare(Song a, Song b){
return a.getTitle().compareTo(b.getTitle());
}
});
SongAdapter songAdt = new SongAdapter(this, songList);
songView.setAdapter(songAdt);
nextactivity=findViewById(R.id.mediacontroller);
nextactivity.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent=new Intent(MainActivity.this,Main2Activity.class);
startActivity(intent);
}
});
songView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
});
}
//song info method retrive
public void getSongList() {
//retrieve song info
ContentResolver musicResolver = getContentResolver();
Uri musicUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Cursor musicCursor = musicResolver.query(musicUri, null, null, null, null);
if (musicCursor != null && musicCursor.moveToFirst()) {
//get columns
int titleColumn = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media.TITLE);
int idColumn = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media._ID);
int artistColumn = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media.ARTIST);
int dataColumn = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media.DATA);
//add songs to list
do {
long thisId = musicCursor.getLong(idColumn);
String thisTitle = musicCursor.getString(titleColumn);
String thisArtist = musicCursor.getString(artistColumn);
String thisPath = musicCursor.getString(dataColumn);
songList.add(new Song(thisId, thisTitle, thisArtist, thisPath));
}
while (musicCursor.moveToNext());
}
}
}
package music.player.musicplayer;
public class Song {
private long id;
private String title;
private String artist;
private String getpath;
public long getId() {
return id;
}
public String getTitle() {
return title;
}
public String getArtist() {
return artist;
}
public String getGetpath() {
return getpath;
}
public Song(long id, String title, String artist, String getpath ) {
this.id = id;
this.title = title;
this.artist = artist;
this.getpath = getpath;
}
}
package music.player.musicplayer;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.util.ArrayList;
class SongAdapter extends BaseAdapter{
private ArrayList<Song> songs;
private LayoutInflater songInf;
public SongAdapter(Context c, ArrayList<Song> theSongs){
songs=theSongs;
songInf=LayoutInflater.from(c);
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return songs.size();
}
#Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
RelativeLayout songLay = (RelativeLayout)songInf.inflate(R.layout.song, parent, false);
//get title and artist views
TextView songView = (TextView)songLay.findViewById(R.id.song_title);
TextView artistView = (TextView)songLay.findViewById(R.id.song_artist);
//get song using position
Song currSong = songs.get(position);
//get title and artist strings
songView.setText(currSong.getTitle());
artistView.setText(currSong.getArtist());
//set position as tag
songLay.setTag(position);
return songLay;
}
}
Here is my activities picture you get idea what i actually i want
actity two:
I would like to display all the registerEventName inside the spinner in order to let the user to select from it. But how to get the data from firebase and display inside the spinner? Hope someone can help me on this.
XML File
For example i want to change EditText of eventTitle to spinner.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/createEventLayout"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:weightSum="10"
android:background="#89bcd4"
android:padding="10dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="4"
android:text="Title of event"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/eventTitle"
android:layout_width="0dp"
android:inputType="text"
android:maxLines="1"
android:lines="1"
android:layout_weight="6"
android:imeOptions="actionNext"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:weightSum="10"
android:background="#dce2e6"
android:padding="10dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="4"
android:text="#string/createEventDesc"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/eventDes"
android:layout_width="0dp"
android:layout_weight="6"
android:lines="1"
android:inputType="text"
android:maxLines="1"
android:imeOptions="actionNext"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:weightSum="10"
android:background="#89bcd4"
android:padding="10dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="4"
android:text="#string/createEventLocation"
android:layout_height="wrap_content" />
<EditText
android:maxLines="1"
android:lines="1"
android:id="#+id/eventLocation"
android:layout_width="0dp"
android:layout_weight="6"
android:inputType="text"
android:imeOptions="actionNext"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:weightSum="10"
android:background="#dce2e6"
android:padding="10dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="4"
android:text="Employee email"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/eventAttendee"
android:layout_width="0dp"
android:layout_weight="6"
android:hint="Place more attendee by comma seprated"
android:maxLines="1"
android:lines="1"
android:inputType="textEmailAddress"
android:imeOptions="actionNext"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:background="#89bcd4"
android:padding="10dp"
android:layout_height="wrap_content">
<TextView
android:id="#+id/startAt"
android:layout_width="0dp"
android:layout_weight="3"
android:text="#string/createEventStart"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="7"
android:layout_height="wrap_content">
<DatePicker
android:id="#+id/startDate"
android:layout_width="wrap_content"
android:calendarViewShown="false"
android:datePickerMode="spinner"
android:layout_weight="4"
android:layout_height="wrap_content" />
<TimePicker
android:id="#+id/startTime"
android:layout_width="wrap_content"
android:layout_weight="4"
android:timePickerMode="spinner"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:background="#dce2e6"
android:padding="10dp"
android:layout_height="wrap_content">
<TextView
android:id="#+id/endAt"
android:layout_width="0dp"
android:layout_weight="3"
android:text="#string/createEventEnd"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="0dp"
android:orientation="vertical"
android:layout_weight="7"
android:layout_height="wrap_content">
<DatePicker
android:id="#+id/endDate"
android:layout_width="wrap_content"
android:calendarViewShown="false"
android:datePickerMode="spinner"
android:layout_height="wrap_content" />
<TimePicker
android:id="#+id/endTime"
android:timePickerMode="spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:weightSum="10"
android:background="#89bcd4"
android:padding="10dp"
android:layout_height="wrap_content">
<Button
android:maxLines="1"
android:id="#+id/createEvent"
android:layout_width="0dp"
android:layout_weight="5"
android:text="Create Event"
android:layout_height="wrap_content" />
<Button
android:id="#+id/cancelEvent"
android:layout_width="0dp"
android:layout_weight="5"
android:text="Cancel"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Event List Adapter Java File
package com.example.edward.neweventmanagementsystem.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.BaseAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import com.example.edward.neweventmanagementsystem.R;
import com.example.edward.neweventmanagementsystem.Model.ScheduledEvents;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Khushvinders on 21-Oct-16.
*/
public class EventListAdapter extends BaseAdapter {
private Context context;
private List<ScheduledEvents> scheduledEvents;
private LayoutInflater inflater;
FirebaseDatabase database;
public EventListAdapter(Context context, List<ScheduledEvents> scheduledEvents){
this.context = context;
this.scheduledEvents = scheduledEvents;
inflater = LayoutInflater.from(this.context);
}
#Override
public int getCount() {
return scheduledEvents.size();
}
#Override
public Object getItem(int i) {
return scheduledEvents.get(i);
}
#Override
public long getItemId(int i) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
EventHolder eventHolder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.event_view_layout, parent, false);
eventHolder = new EventHolder(convertView);
convertView.setTag(eventHolder);
} else {
eventHolder = (EventHolder) convertView.getTag();
}
ScheduledEvents scheduledEvents = (ScheduledEvents) getItem(position);
eventHolder.eventTitle.setText(scheduledEvents.getEventSummery());
eventHolder.eventDes.setText(scheduledEvents.getDescription());
eventHolder.eventAttendee.setText(scheduledEvents.getAttendees());
eventHolder.eventStart.setText(scheduledEvents.getStartDate());
eventHolder.eventEnd.setText(scheduledEvents.getEndDate());
eventHolder.eventLocation.setText(scheduledEvents.getLocation());
return convertView;
}
private class EventHolder {
TextView eventDes, eventAttendee, eventStart, eventEnd, eventLocation, eventTitle;
public EventHolder(View item) {
eventTitle = (TextView) item.findViewById(R.id.eventTitle);
eventDes = (TextView) item.findViewById(R.id.eventDes);
eventAttendee = (TextView) item.findViewById(R.id.eventAttendee);
eventStart = (TextView) item.findViewById(R.id.eventStart);
eventEnd = (TextView) item.findViewById(R.id.eventEnd);
eventLocation = (TextView) item.findViewById(R.id.eventLocation);
}
}
}
Sample of firebase database
I have a ScrollView defined by the xml. Inside of it I want to have two textView like in this photo :
Doing that in xml is fine. But how to add them programmatically? Here's what the code look like without the two TextView example:
.xml file :
<?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/rl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
tools:context=".InventoryActivity">
<ImageView
android:id="#+id/imageView9"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
app:srcCompat="#drawable/inventorylayoutbg" />
<ImageView
android:id="#+id/imageView33"
android:layout_width="61dp"
android:layout_height="59dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:onClick="closeDialog"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.254"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.927"
app:srcCompat="#drawable/blank" />
<ScrollView
android:id="#+id/sv"
android:layout_width="326dp"
android:layout_height="374dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/imageView9">
<LinearLayout
android:id="#+id/ll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"></LinearLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>
.java file
package com.example.jsciampi.tapper;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ScrollView;
public class InventoryActivity extends AppCompatActivity {
//Form
ScrollView sv;
LinearLayout ll;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_inventory);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = (int)(dm.widthPixels*.9);
int height = (int)(dm.heightPixels*.8);
getWindow().setLayout(width,height);
sv = findViewById(R.id.sv);
ll = findViewById(R.id.ll);
for(int i = 0; i < 5; i++){
Button b = new Button(InventoryActivity.this);
//Add Constraint there
ll.addView(b);
}
}
public void closeDialog(View view) {
finish();
}
}
The second TextView had this xml config:
<TextView
android:id="#+id/textView2"
android:layout_width="324dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="#+id/sv"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/firstText"
app:layout_constraintVertical_bias="0.0" />
and I really just need to converto from xml to java this part here :
app:layout_constraintBottom_toBottomOf="#+id/sv"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/aads"
app:layout_constraintVertical_bias="0.0"
Can anyone help me out?
for (int i = 0; i < 5; i++) {
View row = LayoutInflater.from(this).inflate(R.layout.image_text_row,null,false);
ll.addView(row);
}
add the below layout to file with name image_text_row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/background_dark"
android:orientation="horizontal">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:src="#android:drawable/ic_dialog_email" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Text"
android:textColor="#android:color/white"
android:textSize="20sp" />
</LinearLayout>
This is kind of beginner/noob question, but I want to use InputActivity.java and activity_input.xml as the one that the user use to input data. The code for the input are as shown below:
InputActivity.java
package com.lukmanyahoo.denny.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class InputActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_input);
}
//Send data to HasilActivity.java
}
activity_input.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.lukmanyahoo.denny.myapplication.InputActivity">
<EditText
android:id="#+id/editText"
android:layout_width="569dp"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginLeft="636dp"
android:layout_marginStart="16dp"
android:layout_marginTop="15dp"
android:ems="10"
android:hint="#string/umur"
android:inputType="number"
app:layout_constraintBottom_toTopOf="#+id/editText"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="DuplicateIds,NotSibling,RtlHardcoded"
app:layout_constraintVertical_bias="0.251" />
<EditText
android:id="#+id/editText2"
android:layout_width="569dp"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="#string/daerah"
android:inputType="textPersonName"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#+id/editText"
tools:ignore="MissingConstraints,RtlHardcoded" />
<TextView
android:id="#+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:text="#string/jurusan"
android:textSize="30sp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:ignore="MissingConstraints"
android:layout_marginTop="32dp"
app:layout_constraintTop_toBottomOf="#+id/editText2"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp" />
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="569dp"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView"
tools:ignore="RtlHardcoded">
<RadioButton
android:id="#+id/radioButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/informatika" />
<RadioButton
android:id="#+id/radioButton2"
android:layout_width="569dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/sistem_informasi"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="178dp" />
</RadioGroup>
<Button
android:id="#+id/button3"
android:layout_width="569dp"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="#string/kirim"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#+id/radioGroup"
tools:ignore="RtlHardcoded" />
</android.support.constraint.ConstraintLayout>
The code for the output part of my application are shown below:
HasilActivity.java
package com.lukmanyahoo.denny.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class HasilActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hasil);
}
}
activity_hasil.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.lukmanyahoo.denny.myapplication.HasilActivity">
<TableLayout
android:layout_width="568dp"
android:layout_height="791dp"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/umur"
android:textStyle="bold" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" "
tools:layout_editor_absoluteX="58dp"
tools:layout_editor_absoluteY="169dp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/daerah"
android:textStyle="bold" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" " />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/jurusan"
android:textStyle="bold" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" " />
</TableRow>
</TableLayout>
</android.support.constraint.ConstraintLayout>
Thanks for taking time answering this. I am new in giving question here.
In your InputActivity
public class InputActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_input);
}
//Send data to HasilActivity.java
Intent intent = new Intent(this, HasilActivity.class);
// put your data here
intent.putExtra("value_one", editText.getText().toString().trim());
intent.putExtra("value_two", editText2.getText().toString().trim());
startActivity(intent)
}
and in your HasilActivity
public class HasilActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hasil);
String value = getIntent().getStringExtra("value_one");
String value2 = getIntent().getStringExtra("value_two");
}
}
that is :)