Only shows one tetview rating - java

I am developing an app to help people know when it is time for a phone upgrade. I ran into a little problem along the way, mainly when trying to test the functionality of the code. I rated all 6 categories and pressed the continue button. Only the rating for the "Game" shows up. I don't know what is going on since I have all six textviews included.
Shows only one rating
Java:
package com.inducesmile.phoneupgrade;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.RatingBar;
import android.widget.TextView;
public class Page1 extends Activity {
TextView tvBatt, tvPerf, tvAttr, tvCam, tvVal, tvGame;
RatingBar rateBattery, ratePerformance, rateCamera, rateValue, rateGaming, rateAttractiveness;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.page1);
Init();
}
public void Init() {
tvBatt = (TextView) findViewById(R.id.tvBatt);
tvPerf = (TextView) findViewById(R.id.tvPerf);
tvAttr = (TextView) findViewById(R.id.tvAttr);
tvCam = (TextView) findViewById(R.id.tvCam);
tvVal = (TextView) findViewById(R.id.tvVal);
tvGame = (TextView) findViewById(R.id.tvGame);
rateBattery = (RatingBar) findViewById(R.id.rateBatt);
rateCamera = (RatingBar) findViewById(R.id.rateCam);
rateGaming = (RatingBar) findViewById(R.id.rateGame);
rateValue = (RatingBar) findViewById(R.id.rateValue);
ratePerformance = (RatingBar) findViewById(R.id.Performance);
rateAttractiveness = (RatingBar) findViewById(R.id.rateAttr);
}
public void onButtonClick(View v) {
if (v.getId() == R.id.btnCont) {
String strBatt = String.valueOf(rateBattery.getRating());
tvBatt.setText(strBatt);
String strAttr = String.valueOf(rateAttractiveness.getRating());
tvAttr.setText(strAttr);
String strCam = String.valueOf(rateCamera.getRating());
tvCam.setText(strCam);
String strPerf = String.valueOf(ratePerformance.getRating());
tvPerf.setText(strPerf);
String strGame = String.valueOf(rateGaming.getRating());
tvGame.setText(strGame);
String strVal = String.valueOf(rateValue.getRating());
tvVal.setText(strVal);
}
}
}
xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:onClick="onButtonClick"
android:background="#FFF000">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="How Important Are These Features to You?"
android:id="#+id/textView2"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textStyle="bold"
android:textColor="#000000"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Continue"
android:textColor="#FFFFFF"
android:id="#+id/btnCont"
android:background="#drawable/buttonshape"
android:onClick="onButtonClick"
android:layout_below="#+id/Performance"
android:layout_centerHorizontal="true"
android:layout_marginTop="34dp" />
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/rateBatt"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:stepSize="0.5"
android:layout_below="#+id/textView2" />
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/rateGame"
android:stepSize="0.5"
android:layout_below="#+id/rateBatt"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/rateCam"
android:layout_alignLeft="#+id/rateGame"
android:layout_alignStart="#+id/rateGame"
android:stepSize="0.5"
android:layout_below="#+id/rateGame" />
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/rateAttr"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:stepSize="0.5"
android:layout_below="#+id/rateCam" />
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/rateValue"
android:layout_below="#+id/rateAttr"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/Performance"
android:layout_below="#+id/rateValue"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Battery Life:"
android:id="#+id/textView3"
android:layout_below="#+id/textView2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="21dp"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Gaming:"
android:id="#+id/textView4"
android:layout_alignTop="#+id/rateGame"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="16dp"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Camera:"
android:id="#+id/textView5"
android:layout_below="#+id/rateGame"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="11dp"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Attractiveness:"
android:id="#+id/textView6"
android:layout_marginTop="14dp"
android:layout_alignTop="#+id/rateAttr"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Value:"
android:id="#+id/textView7"
android:layout_alignTop="#+id/rateValue"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="11dp"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Performance:"
android:id="#+id/textView8"
android:layout_below="#+id/rateValue"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="12dp"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvBatt"
android:layout_alignTop="#+id/textView3"
android:layout_toRightOf="#+id/textView3"
android:layout_toEndOf="#+id/textView3"
android:text="____" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvGame"
android:layout_alignBottom="#+id/textView4"
android:layout_toRightOf="#+id/textView4"
android:layout_toEndOf="#+id/textView4"
android:text="____" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvCam"
android:layout_alignBottom="#+id/textView5"
android:layout_toRightOf="#+id/textView5"
android:layout_toEndOf="#+id/textView5"
android:text="____" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvAttr"
android:layout_below="#+id/textView6"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="____" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvVal"
android:layout_alignBottom="#+id/textView7"
android:layout_toRightOf="#+id/textView7"
android:layout_toEndOf="#+id/textView7"
android:text="____" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvPerf"
android:layout_alignBottom="#+id/textView8"
android:layout_toRightOf="#+id/textView8"
android:layout_toEndOf="#+id/textView8"
android:text="____" />

Your code is fine, try rebuild/clean the project.
If you're using Android Studio, go to Build -> Clean Project and then Build -> Rebuild Project.

Related

Horizontally Scrolling Text Performance Issues

My app contains a few textViews which are supposed to be scrolling horizontally. This works when my layout is first loaded but after clicking on a button to load another layout and then re-click on that button to load back the first layout those textViews start scrolling after a "big" delay(like 20 secs+). I'm trying to figure out the source of this problem with the Layout Inspector, Hierarchy Viewer etc. but no luck.
UPDATE: I noticed something strange today.When i go from the 1st layout to the 2nd one and vice versa, although the TextViews stop scrolling, if i close and re-open the phone's screen, the scrolling works like a charm. This seems totally strange to me, do you know what's causing this and why?
CardViewActivity.java:
public class CardViewActivity extends AppCompatActivity {
private ImageView cardArtImageView;
private TextView leaderSkillDescText;
private TextView superAttackTitleText;
private TextView superAttackDescText;
private TextView passiveSkillTitleText;
private TextView passiveSkillDescText;
private TextView hpText;
private TextView attText;
private TextView defText;
private TextView costText;
private Button arrowButton;
private int selectedItemPosition;
private boolean isBtnClicked = false;
// Listener member field for each layout's button. This listener will be used recursively
private View.OnClickListener arrowButtonListener = new View.OnClickListener() {
#Override
public void onClick(View view) {
// When the arrowButton is clicked, choose the right layout based on the button's state
int resID = isBtnClicked ? R.layout.cardview_refined : R.layout.cardview_expand_details;
setContentView(resID);
// If we're in the first layout, initialize the cardArtImageView field
if(isBtnClicked) {
cardArtImageView = findViewById(R.id.cardArtImageView);
}
viewDefinitions(!isBtnClicked);
initCardViewData(selectedItemPosition);
setSelectedViewsInit();
// Set the arrowButton's listener to this listener (recursively)
arrowButton.setOnClickListener(arrowButtonListener);
// toggle our flag field
isBtnClicked = !isBtnClicked;
}
};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cardview_refined);
// Retrieving the data sent over from MainActivity
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
if (bundle != null) {
selectedItemPosition = bundle.getInt("Card Index");
}
//Toast.makeText(this, "WIDTH: " + SCREEN_WIDTH, Toast.LENGTH_SHORT).show();
// Initializing our views
cardArtImageView = findViewById(R.id.cardArtImageView);
viewDefinitions(false);
setSelectedViewsInit();
initCardViewData(selectedItemPosition);
arrowButton.setOnClickListener(arrowButtonListener);
}
/**
* Sets the required textViews as selected to allow automatic scrolling
*/
private void setSelectedViewsInit() {
leaderSkillDescText.setSelected(true);
superAttackTitleText.setSelected(true);
superAttackDescText.setSelected(true);
if (passiveSkillTitleText != null && passiveSkillDescText != null) {
passiveSkillTitleText.setSelected(true);
passiveSkillDescText.setSelected(true);
}
}
/**
* Adds the views's definitions
*
* #param initPassiveInfo used to decide whether or not the passiveSkillDesc & ..Title != null
* so that they can be defined
*/
private void viewDefinitions(boolean initPassiveInfo) {
leaderSkillDescText = findViewById(R.id.leaderSkillDesc);
superAttackTitleText = findViewById(R.id.superAttackTitle);
superAttackDescText = findViewById(R.id.superAttackDesc);
if (initPassiveInfo) {
passiveSkillTitleText = findViewById(R.id.passiveSkillTitle);
passiveSkillDescText = findViewById(R.id.passiveSkillDesc);
} else {
Log.d("Definitions", "Passive info == null");
}
hpText = findViewById(R.id.HP);
attText = findViewById(R.id.ATT);
defText = findViewById(R.id.DEF);
costText = findViewById(R.id.COST);
arrowButton = findViewById(R.id.arrowButton);
}
/**
* Initialize the cardViewActivity's views with the data from the CardInfoDatabase.java class
*
* #param selectedItemPosition Used to initialize this activity's views if the intent was called from the MainScreen Fragment
*/
private void initCardViewData(int selectedItemPosition) {
if (cardArtImageView != null) {
cardArtImageView.setImageResource(CardInfoDatabase.cardArts[selectedItemPosition]);
}
leaderSkillDescText.setText(CardInfoDatabase.leaderSkills[selectedItemPosition]);
superAttackTitleText.setText(CardInfoDatabase.superAttacksName[selectedItemPosition]);
superAttackDescText.setText(CardInfoDatabase.superAttacksDesc[selectedItemPosition]);
if (passiveSkillTitleText != null && passiveSkillDescText != null) {
passiveSkillTitleText.setText(CardInfoDatabase.passiveSkillsName[selectedItemPosition]);
passiveSkillDescText.setText(CardInfoDatabase.passiveSkillsDesc[selectedItemPosition]);
}
hpText.setText(CardInfoDatabase.hp[selectedItemPosition].toString());
attText.setText(CardInfoDatabase.att[selectedItemPosition].toString());
defText.setText(CardInfoDatabase.def[selectedItemPosition].toString());
costText.setText(CardInfoDatabase.cost[selectedItemPosition].toString());
}
}
firstLayout.xml:
<?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"
android:background="#drawable/card_view_bg"
tools:layout_editor_absoluteY="25dp">
<ImageView
android:id="#+id/cardArtImageView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
app:layout_constraintBottom_toTopOf="#+id/cardDetailsImageView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="#string/card_image" />
<!--
<ImageView
android:id="#+id/cardDetailsImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:cropToPadding="false"
android:scaleType="fitXY"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="#drawable/card_details_box" /> -->
<!-- Implement scrolling text
android:focusable="true"
android:focusableInTouchMode="true"
android:singleLine="true"
android:scrollHorizontally="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
-->
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="225dp"
android:background="#drawable/card_details_closed">
<TextView
android:id="#+id/COST"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/leaderSkillDesc"
android:layout_marginBottom="9dp"
android:layout_toEndOf="#+id/superAttackDesc"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:text="00"
android:textColor="#color/white"
android:textSize="17sp"
android:textStyle="bold" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true">
<TextView
android:id="#+id/HP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="33dp"
android:fontFamily="monospace"
android:text="0000"
android:textColor="#color/white"
android:textSize="18sp"
android:textStyle="bold"
tools:text="0000" />
<TextView
android:id="#+id/ATT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginStart="73dp"
android:layout_toEndOf="#+id/HP"
android:fontFamily="monospace"
android:text="0000"
android:textColor="#color/white"
android:textSize="18sp"
android:textStyle="bold"
tools:text="0000" />
<TextView
android:id="#+id/DEF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="42dp"
android:fontFamily="monospace"
android:text="0000"
android:textColor="#color/white"
android:textSize="18sp"
android:textStyle="bold"
tools:text="0000" />
</RelativeLayout>
<TextView
android:id="#+id/leaderSkillDesc"
android:layout_width="250dp"
android:layout_height="15dp"
android:layout_above="#+id/superAttackTitle"
android:layout_alignParentEnd="true"
android:layout_marginBottom="13dp"
android:layout_marginEnd="37dp"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:fontFamily="monospace"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAlignment="viewStart"
android:textColor="#color/white"
android:textSize="13sp"
android:textStyle="italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.496"
app:layout_constraintVertical_bias="0.626" />
<TextView
android:id="#+id/superAttackTitle"
android:layout_width="245dp"
android:layout_height="15dp"
android:layout_above="#+id/superAttackDesc"
android:layout_alignStart="#+id/superAttackDesc"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:fontFamily="monospace"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAlignment="viewStart"
android:textColor="#android:color/holo_blue_light"
android:textSize="12sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/superAttackDesc"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
<TextView
android:id="#+id/superAttackDesc"
android:layout_width="255dp"
android:layout_height="15dp"
android:layout_alignEnd="#+id/leaderSkillDesc"
android:layout_alignParentBottom="true"
android:layout_marginBottom="74dp"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:fontFamily="monospace"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAlignment="viewStart"
android:textColor="#android:color/white"
android:textSize="13sp"
android:textStyle="italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
<Button
android:id="#+id/arrowButton"
android:layout_width="60dp"
android:layout_height="35dp"
android:layout_alignParentBottom="true"
android:layout_alignStart="#+id/leaderSkillDesc"
android:layout_marginBottom="7dp"
android:layout_marginStart="75dp"
android:background="#drawable/arrow_up"
android:textOff=""
android:textOn="" />
</RelativeLayout>
</LinearLayout>
SecondLayout.xml:
<?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"
android:orientation="vertical"
android:background="#drawable/card_view_bg"
tools:layout_editor_absoluteY="25dp">
<!-- Implement scrolling text
android:focusable="true"
android:focusableInTouchMode="true"
android:singleLine="true"
android:scrollHorizontally="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
-->
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/card_details_open">
<TextView
android:id="#+id/COST"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/relativeLayout3"
android:layout_marginTop="48dp"
android:layout_toEndOf="#+id/superAttackDesc"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:text="00"
android:textColor="#color/white"
android:textSize="17sp"
android:textStyle="bold" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:id="#+id/relativeLayout3">
<TextView
android:id="#+id/HP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="33dp"
android:fontFamily="monospace"
android:text="0000"
android:textColor="#color/white"
android:textSize="18sp"
android:textStyle="bold"
tools:text="0000" />
<TextView
android:id="#+id/ATT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginStart="73dp"
android:layout_toEndOf="#+id/HP"
android:fontFamily="monospace"
android:text="0000"
android:textColor="#color/white"
android:textSize="18sp"
android:textStyle="bold"
tools:text="0000" />
<TextView
android:id="#+id/DEF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="42dp"
android:fontFamily="monospace"
android:text="0000"
android:textColor="#color/white"
android:textSize="18sp"
android:textStyle="bold"
tools:text="0000" />
</RelativeLayout>
<TextView
android:id="#+id/leaderSkillDesc"
android:layout_width="250dp"
android:layout_height="15dp"
android:layout_alignParentEnd="true"
android:layout_below="#+id/COST"
android:layout_marginEnd="36dp"
android:layout_marginTop="16dp"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:fontFamily="monospace"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAlignment="viewStart"
android:textColor="#color/white"
android:textSize="13sp"
android:textStyle="italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.496"
app:layout_constraintVertical_bias="0.626" />
<TextView
android:id="#+id/superAttackTitle"
android:layout_width="245dp"
android:layout_height="15dp"
android:layout_alignStart="#+id/leaderSkillDesc"
android:layout_below="#+id/leaderSkillDesc"
android:layout_marginTop="23dp"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:fontFamily="monospace"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAlignment="viewStart"
android:textColor="#android:color/holo_blue_light"
android:textSize="12sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/superAttackDesc"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/superAttackDesc"
android:layout_width="255dp"
android:layout_height="15dp"
android:layout_alignStart="#+id/superAttackTitle"
android:layout_below="#+id/superAttackTitle"
android:layout_marginTop="5dp"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:fontFamily="monospace"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAlignment="viewStart"
android:textColor="#android:color/white"
android:textSize="13sp"
android:textStyle="italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/passiveSkillTitle"
android:layout_width="255dp"
android:layout_height="17dp"
android:layout_alignStart="#+id/superAttackDesc"
android:layout_below="#+id/superAttackDesc"
android:layout_marginBottom="3dp"
android:layout_marginStart="8dp"
android:layout_marginTop="23dp"
android:background="#color/passiveSkillNameBackground"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:fontFamily="monospace"
android:marqueeRepeatLimit="marquee_forever"
android:paddingLeft="7dp"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAlignment="viewStart"
android:textColor="#android:color/holo_blue_light"
android:textColorHighlight="#android:color/black"
android:textSize="13sp"
android:textStyle="italic"
android:visibility="visible"
tools:layout_editor_absoluteX="207dp"
tools:layout_editor_absoluteY="543dp" />
<TextView
android:id="#+id/passiveSkillDesc"
android:layout_width="250dp"
android:layout_height="15dp"
android:layout_alignStart="#+id/passiveSkillTitle"
android:layout_below="#+id/passiveSkillTitle"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:fontFamily="monospace"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="13sp"
android:textStyle="italic"
android:visibility="visible"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="602dp" />
<Button
android:id="#+id/arrowButton"
android:layout_width="60dp"
android:layout_height="35dp"
android:layout_alignParentBottom="true"
android:layout_alignStart="#+id/leaderSkillDesc"
android:layout_marginBottom="7dp"
android:layout_marginStart="75dp"
android:background="#drawable/arrow_down"
android:textOff=""
android:textOn="" />
</RelativeLayout>
</RelativeLayout>
I'd suggest using a RecyclerView with a custom Adapter, RecyclerView can be used vertically or horizontally.

storing value of EditText to a string variable is not working

My question is different from other questions previously asked on this site on the same topic. The answer as to how we can store text from EditText field to a string was given as
EditText input = (EditText) findViewById(R.id.inputId);
String str = input.getText().toString();
my question is a bit different.
my java main activity is:
package com.example.fahadsaleem.xyz;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import org.w3c.dom.Text;
public class MainActivity extends AppCompatActivity {
public String str;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView calc_monday = (TextView) findViewById(R.id.monday_calc);
calc_monday.setOnClickListener(
new Button.OnClickListener(){
public void onClick(View v){
CustomDialogClass cdd = new CustomDialogClass(MainActivity.this);
cdd.show();
TextView text1 = (TextView) cdd.findViewById(R.id.Subject_ID);
text1.setText(str);
TextView text2 = (TextView) cdd.findViewById(R.id.Room_ID);
text2.setText("6 (SEECS)");
TextView text3 = (TextView) cdd.findViewById(R.id.Time_ID);
text3.setText("09:00am 09:50am");
}
}
);
calc_monday.setOnLongClickListener(
new Button.OnLongClickListener() {
public boolean onLongClick(View v) {
kj monday_calc = new kj(MainActivity.this);
monday_calc.show();
return true;
}
}
);
}
}
The kj class has the following code:
package com.example.fahadsaleem.xyz;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
/**
* Created by Fahad Saleem on 12/22/2015.
*/
public class kj extends Dialog implements android.view.View.OnClickListener {
public Activity c;
public Dialog d;
public Button back;
public kj(Activity a) {
super(a);
// TODO Auto-generated constructor stub
this.c = a;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.setting_dialog);
back = (Button) findViewById(R.id.set_btnn);
back.setOnClickListener(this);
}
#Override
public void onClick(View v){
switch (v.getId()){
case R.id.set_btnn:
MainActivity police = new MainActivity();
EditText set_monday_calc = (EditText) findViewById(R.id.set_Subject_ID);
// Store EditText in Variable
police.str = set_monday_calc.getText().toString();
dismiss();
break;
default:
break;
}
dismiss();
}
}
Basically the app's interface has a time table of subjects. When you click on a subject name, a dialog box appears showing 3 things: Subject name, room number and time period.
Now what I want is I should be able to change the 3 things by making a long click on the subject name. I am trying to use this button in class kj to achieve that:
case R.id.set_btnn:
MainActivity police = new MainActivity();
EditText set_monday_calc = (EditText) findViewById(R.id.set_Subject_ID);
// Store EditText in Variable
police.str = set_monday_calc.getText().toString();
dismiss();
this variable str is declared in MainActivity java file. When the user enters the text on the subject name and clicks on this button, the text should be stored in the str variable.
But this is not happening. When I start writing any text on the EditText field on my interface which looks like this:
The following error is seen in the log:
then when I click Go Back button which should set the text I wrote to variable str, the following error is seen in the log:
Later on when I single click on the subject, what I wrote before I clicked on the button is not being showed, rather a blank space is being shown as was declared by this line in mainactivity java file:
public String str;
Like this:
What is the problem? Here are the rest of the files:
CustomDialogClass:
package com.example.fahadsaleem.xyz;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
/**
* Created by Fahad Saleem on 12/22/2015.
*/
public class CustomDialogClass extends Dialog implements android.view.View.OnClickListener {
public Activity c;
public Dialog d;
public Button back;
public CustomDialogClass(Activity a) {
super(a);
// TODO Auto-generated constructor stub
this.c = a;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.custom_dialog);
back = (Button) findViewById(R.id.btnn);
back.setOnClickListener(this);
}
#Override
public void onClick(View v){
switch (v.getId()){
case R.id.btnn:
dismiss();
break;
default:
break;
}
dismiss();
}
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.example.fahadsaleem.xyz.MainActivity">
<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/gridLayout">
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="Thursday"
android:id="#+id/textView5"
android:layout_row="0"
android:layout_column="5"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="120dp"
android:layout_height="27dp"
android:text="Time"
android:id="#+id/textView"
android:layout_row="0"
android:layout_column="0"
android:textAlignment="center"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="Friday"
android:id="#+id/textView6"
android:layout_row="0"
android:layout_column="6"
android:layout_gravity="center"
android:gravity="center" />
<TextView
android:layout_width="120dp"
android:layout_height="27dp"
android:text="900-950"
android:id="#+id/textView7"
android:layout_row="1"
android:layout_column="0"
android:textAlignment="center"
android:layout_gravity="center|fill"
android:gravity="center"
android:background="#daf8a6" />
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="Monday"
android:id="#+id/textView2"
android:layout_row="0"
android:layout_column="1"
android:textAlignment="center"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="Tuesday"
android:id="#+id/textView3"
android:layout_row="0"
android:layout_column="2"
android:gravity="center"
android:layout_gravity="center" />
<TextView
android:layout_width="100dp"
android:layout_height="27dp"
android:text="Wednesday"
android:id="#+id/textView4"
android:layout_row="0"
android:layout_column="3"
android:layout_gravity="center|fill"
android:gravity="center"/>
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="Calculus"
android:id="#+id/monday_calc"
android:layout_row="1"
android:layout_column="1"
android:textAlignment="center"
android:layout_gravity="center|fill"
android:gravity="center"
android:clickable="true"
android:background="#dbfbb8" />
<TextView
android:layout_width="80dp"
android:layout_height="50dp"
android:text="Programming"
android:id="#+id/Tuesday_Prog"
android:layout_row="1"
android:layout_column="2"
android:layout_rowSpan="2"
android:layout_gravity="center|fill"
android:gravity="center"
android:textSize="13dp" />
<TextView
android:layout_width="100dp"
android:layout_height="27dp"
android:text="Library"
android:id="#+id/textView25"
android:layout_row="1"
android:layout_column="3"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Islamiat"
android:id="#+id/Thursday_Islamiat"
android:layout_row="1"
android:layout_column="5"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="Library"
android:id="#+id/poqwe"
android:layout_row="1"
android:layout_column="6"
android:layout_gravity="center"
android:gravity="center" />
<TextView
android:layout_width="120dp"
android:layout_height="27dp"
android:text="1000-1050"
android:id="#+id/textView8"
android:layout_row="2"
android:layout_column="0"
android:textAlignment="center"
android:layout_gravity="center|fill"
android:gravity="center"
android:background="#e0fcbb" />
<TextView
android:layout_width="80dp"
android:layout_height="75dp"
android:text="ICT Lab"
android:id="#+id/Monday_ICT"
android:layout_row="2"
android:layout_column="1"
android:layout_rowSpan="3"
android:textAlignment="center"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="100dp"
android:layout_height="27dp"
android:text="Calculus"
android:id="#+id/Wed_calc"
android:layout_row="2"
android:layout_column="3"
android:gravity="center"
android:layout_gravity="bottom" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calculus"
android:id="#+id/Thursday_calc"
android:layout_row="2"
android:layout_column="5"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="Islamiat"
android:id="#+id/fri_islamiat"
android:layout_row="2"
android:layout_column="6"
android:layout_gravity="center"
android:gravity="center" />
<TextView
android:layout_width="120dp"
android:layout_height="27dp"
android:text="1100-1150"
android:id="#+id/textView9"
android:layout_row="3"
android:layout_column="0"
android:textAlignment="center"
android:layout_gravity="center|fill"
android:gravity="center"
android:background="#daf8a6" />
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="Library"
android:id="#+id/textView21"
android:layout_row="3"
android:layout_column="2"
android:gravity="center"
android:layout_gravity="bottom" />
<TextView
android:layout_width="100dp"
android:layout_height="27dp"
android:text="Tutorial"
android:id="#+id/textView27"
android:layout_row="3"
android:layout_column="3"
android:layout_gravity="left|bottom"
android:gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DM"
android:id="#+id/Thursday_DM"
android:layout_row="3"
android:layout_column="5"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="Comm. Skills"
android:id="#+id/fri_comm"
android:layout_row="3"
android:layout_column="6"
android:layout_gravity="center"
android:gravity="center"
android:textSize="13dp" />
<TextView
android:layout_width="120dp"
android:layout_height="27dp"
android:text="1200-1250"
android:id="#+id/textView10"
android:layout_row="4"
android:layout_column="0"
android:textAlignment="center"
android:layout_gravity="center|fill"
android:gravity="center"
android:background="#e0fcbb" />
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="Comm. Skills"
android:id="#+id/Tuesday_Comm"
android:layout_row="4"
android:layout_column="2"
android:layout_gravity="center|fill"
android:gravity="center"
android:textSize="13dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DM"
android:id="#+id/Wed_DM"
android:layout_row="4"
android:layout_column="3"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tutorial"
android:id="#+id/textView33"
android:layout_row="4"
android:layout_column="5"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="Programming"
android:id="#+id/fri_Prog"
android:layout_row="4"
android:layout_column="6"
android:layout_gravity="center"
android:gravity="center"
android:textSize="13dp" />
<TextView
android:layout_width="120dp"
android:layout_height="27dp"
android:text="Lunch + Prayer Break"
android:id="#+id/textView17"
android:layout_row="5"
android:layout_column="0"
android:layout_gravity="center|fill"
android:gravity="center"
android:layout_columnSpan="7"
android:background="#d9f2f1" />
<TextView
android:layout_width="120dp"
android:layout_height="27dp"
android:text="1400-1450"
android:id="#+id/textView13"
android:layout_row="6"
android:layout_column="0"
android:textAlignment="center"
android:layout_gravity="center|fill"
android:gravity="center"
android:background="#daf8a6" />
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="DM"
android:id="#+id/Monday_DM"
android:layout_row="6"
android:layout_column="1"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="80dp"
android:layout_height="50dp"
android:text="ICT Lecture"
android:id="#+id/Tuesday_ICT"
android:layout_row="6"
android:layout_column="2"
android:layout_gravity="center|fill"
android:gravity="center"
android:layout_rowSpan="2" />
<TextView
android:layout_width="100dp"
android:layout_height="75dp"
android:text="Programming Lab"
android:id="#+id/Wed_Prog"
android:layout_row="6"
android:layout_column="3"
android:layout_rowSpan="3"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Library"
android:id="#+id/textView34"
android:layout_row="6"
android:layout_column="5"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Library"
android:id="#+id/textView41"
android:layout_row="6"
android:layout_column="6"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="120dp"
android:layout_height="27dp"
android:text="1500-1550"
android:id="#+id/textView12"
android:layout_row="7"
android:layout_column="0"
android:textAlignment="center"
android:layout_gravity="center|fill"
android:gravity="center"
android:background="#e0fcbb" />
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="Library"
android:id="#+id/textView18"
android:layout_row="7"
android:layout_column="1"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Library"
android:id="#+id/textView35"
android:layout_row="7"
android:layout_column="5"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Library"
android:id="#+id/textView42"
android:layout_row="7"
android:layout_column="6"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="120dp"
android:layout_height="27dp"
android:text="1600-1650"
android:id="#+id/textView14"
android:layout_row="8"
android:layout_column="0"
android:textAlignment="center"
android:layout_gravity="center|fill"
android:gravity="center"
android:background="#daf8a6" />
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="Library"
android:id="#+id/textView19"
android:layout_row="8"
android:layout_column="1"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="Library"
android:id="#+id/textView24"
android:layout_row="8"
android:layout_column="2"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Library"
android:id="#+id/textView36"
android:layout_row="8"
android:layout_column="5"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Library"
android:id="#+id/textView43"
android:layout_row="8"
android:layout_column="6"
android:layout_gravity="center|fill"
android:gravity="center" />
</GridLayout>
setting_dialog.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width= "400dp"
android:layout_height="140dp"
android:background="#3E80B4"
android:orientation="vertical" >
<TextView
android:id="#+id/set_txt_dia"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Subject Name: "
android:textColor="#android:color/white"
android:textSize="15dp"
android:textStyle="bold"
android:layout_above="#+id/set_textView44"
android:layout_toRightOf="#+id/relativeLayout"
android:layout_toEndOf="#+id/relativeLayout"
android:layout_marginLeft="14dp" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#3E80B4"
android:orientation="horizontal"
android:id="#+id/relativeLayout">
</RelativeLayout>
<Button
android:id="#+id/set_btnn"
android:layout_width="83dp"
android:layout_height="46dp"
android:background="#android:color/white"
android:clickable="true"
android:text="Go Back"
android:textColor="#5DBCD2"
android:textStyle="bold"
android:layout_marginRight="37dp"
android:layout_marginEnd="37dp"
android:layout_alignTop="#+id/set_Subject_ID"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="25dp" />
<TextView
android:id="#+id/set_textView15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Time Period: "
android:textColor="#android:color/white"
android:textSize="15dp"
android:textStyle="bold"
android:layout_centerVertical="true"
android:layout_alignLeft="#+id/set_textView44"
android:layout_alignStart="#+id/set_textView44" />
<TextView
android:id="#+id/set_textView44"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Location: "
android:textColor="#android:color/white"
android:textSize="15dp"
android:textStyle="bold"
android:layout_above="#+id/set_textView15"
android:layout_alignLeft="#+id/set_txt_dia"
android:layout_alignStart="#+id/set_txt_dia" />
<EditText
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="#+id/set_Subject_ID"
android:textSize="16dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="152dp"
android:layout_marginTop="5dp" />
<EditText
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="#+id/set_Time_ID"
android:textColor="#ffffff"
android:textSize="16dp"
android:layout_marginLeft="139dp"
android:layout_marginTop="44dp" />
<EditText
android:layout_width="70dp"
android:layout_height="wrap_content"
android:id="#+id/set_Room_ID"
android:textSize="16dp"
android:textColor="#ffffff"
android:layout_marginLeft="114dp"
android:layout_marginTop="24dp" />
I did not post the whole of java main activity, I only posted that which is relevant.
I haven't noticed you're using any database. I see that in your app you need to share data between classes, so MUST HAVE is to use SharedPreferences standard database:
Read please this:
How to use SharedPreferences in Android to store, fetch and edit values
You tried to get a string value which was temporary and available only for specific class. That's your problem. Solution above.
Hope it help
In onClick you are creating a new instance with which you don't really seem to be doing anything.
If you were to have in you kj class something like:
public MainActivity c;
...
public kj(MainActivity a) {
and then in onClick(View v) under "case R.id.set_btnn":
c.str = set_monday_calc.getText().toString();
you would manage to update str.

Updating button in android

I am creating an address Book app but I have a problem. When I am trying to set text to the button it doesn't update on the screen.
Here is a part of my main layout:
public void call(View v){
setContentView(R.layout.call);
Numbers num = new Numbers(cont);
final Names names = new Names(cont);
button = (Button) findViewById(R.id.name1);
if(num.getNumber("1").isEmpty()) {
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
setContentView(R.layout.activity_aseta_numero);
Button button1 = (Button) findViewById(R.id.readyButton);
button1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
EditText text = (EditText) findViewById(R.id.Number);
Numbers j = new Numbers(cont);
j.setNumber(text.getText().toString(), "1");
EditText tex = (EditText) findViewById(R.id.NameField);
names.adName(tex.getText().toString(), "1");
button.setText(names.getNimi("1") + "moi");
setContentView(R.layout.call);
System.out.println(button.getText());
}
});
}
});
}else {
}
Here is my name class:
public class Names extends Activity{
SharedPreferences pres;
Button Nappi;
Context context;
public Names(Context mcontext){
context = mcontext;
pres = context.getSharedPreferences("1",0);
}
public void adName(String name, String place){
SharedPreferences.Editor editor = pres.edit();
editor.putString(name,place);
editor.commit();
System.out.println(pres.getString("1", ""));
}
public String getName(String place){
return pres.getString(place,"");
}
}
and here is my setnumber XML:
<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"
tools:context="oo.seniorlauncher.com.o_seniorlauncher.setnumber">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Syötä"
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:height="100dp"
android:textSize="50dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="numero"
android:id="#+id/textView2"
android:layout_alignParentTop="true"
android:layout_alignBottom="#+id/textView"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:width="250dp"
android:textSize="50dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="ja nimi"
android:id="#+id/textView3"
android:height="100dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="66dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textSize="50dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/NameField"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textSize="50dp"
android:layout_centerVertical="true"
android:text="Nimi" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="#+id/Number"
android:layout_below="#+id/NameField"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textSize="50dp"
android:text="Numero"
android:phoneNumber="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Valmis"
android:id="#+id/readyButton"
android:layout_below="#+id/Number"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textSize="75dp" />
and here is the call layout
<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"
tools:context="oo.seniorlauncher.com.o_seniorlauncher.soita1">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/name1"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:height="100dp"
android:width="200dp"
android:textSize="25dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/name2"
android:height="100dp"
android:width="200dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/name1"
android:layout_toEndOf="#+id/name1"
android:textSize="25dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/name3"
android:height="100dp"
android:width="200dp"
android:textSize="25dp"
android:layout_below="#+id/name1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/name4"
android:height="100dp"
android:width="200dp"
android:textSize="25dp"
android:layout_below="#+id/name1"
android:layout_toRightOf="#+id/name3"
android:layout_toEndOf="#+id/name3" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/name5"
android:height="100dp"
android:width="200dp"
android:textSize="25dp"
android:layout_below="#+id/name3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/name6"
android:height="100dp"
android:width="200dp"
android:textSize="25dp"
android:layout_below="#+id/name3"
android:layout_toRightOf="#+id/name5"
android:layout_toEndOf="#+id/name5" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Home"
android:id="#+id/home1"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="#+id/name6"
android:layout_alignEnd="#+id/name6"
android:height="100dp"
android:textSize="80dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show all numbers"
android:id="#+id/button4"
android:height="100dp"
android:textSize="30dp"
android:layout_below="#+id/name5"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="#+id/home1"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
recreate() and .invalide didn't help.
Thanks in advance.

Menu actions and sums in Android app

So I have been trying to develop an app that adds a select quantity together in a menu, all while in Android studio/eclipse.
I am listing off drinks and to the right of each drink is a "-" (the minus) and "+" (the plus) signs, which are buttons respectively, with a "0" in the middle.
At the bottom of the screen, I have a "Total" section.
I have a screen shot of what the menu appears as thus far:
I am looking to have the + and - buttons affect the number that lies in the middle of them. So when the "+" is pressed it adds 1 and if pressed again, it adds 1 and so on, the "-" button will take 1 away from the number back to zero if need be.
It should be able to tally the total price of each drink all together and output the sum to the
"$ 0.00" near the total. The "Order" button just takes me to another screen, which will be tackled at a later date.
I have tried searching for a good many hours and there are so many links I am drowning that I can not find any help that sticks.
I know that the Java code should use the ID of the EditText's but I am confused as to how.
I will post what code I have for the xml and java code. If there is also a manifest I have to add, I can not find it.
drinkmenu.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:id="#+id/mainmenulayout"
android:background="#34D6D9">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Drinks:"
android:id="#+id/textView"
android:background="#FFFFFF"
android:textStyle="bold"
android:textSize="24dp"
android:layout_toStartOf="#+id/textView2"
android:layout_toLeftOf="#+id/textView2"
android:layout_marginRight="75dp"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/button"
android:layout_alignEnd="#+id/button" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Quantity:"
android:id="#+id/textView2"
android:textSize="24dp"
android:textStyle="bold"
android:background="#FFFFFF"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/orderbtn"
android:layout_alignEnd="#+id/orderbtn" />
<Button
android:layout_width="240dp"
android:layout_height="wrap_content"
android:text="Espresso"
android:id="#+id/button"
android:layout_below="#+id/textView"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="30dp"
android:background="#FFFFFF"
android:textSize="24dp" />
<Button
android:layout_width="240dp"
android:layout_height="wrap_content"
android:text="Macciato"
android:id="#+id/button2"
android:layout_below="#+id/button"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="30dp"
android:textSize="24dp"
android:background="#FFFFFF" />
<Button
android:layout_width="240dp"
android:layout_height="wrap_content"
android:text="Con Panna"
android:id="#+id/button3"
android:layout_below="#+id/button2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="30dp"
android:background="#FFFFFF"
android:textSize="24dp" />
<Button
android:layout_width="240dp"
android:layout_height="wrap_content"
android:text="Americano"
android:id="#+id/button4"
android:layout_below="#+id/button3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="30dp"
android:textSize="24dp"
android:background="#FFFFFF" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:text="Latte"
android:id="#+id/button5"
android:layout_below="#+id/button4"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="30dp"
android:background="#FFFFFF"
android:textSize="24dp" />
<Button
android:layout_width="30dp"
android:layout_height="wrap_content"
android:text="+"
android:id="#+id/button6"
android:layout_alignTop="#+id/button"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#ffff45df"
android:textSize="24dp" />
<EditText
android:layout_width="30dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/editText2"
android:layout_alignTop="#+id/button"
android:layout_toLeftOf="#+id/button6"
android:layout_toStartOf="#+id/button6"
android:text=" 0"
android:textSize="24dp"
android:background="#FFFFFF"
android:layout_above="#+id/button2" />
<Button
android:layout_width="30dp"
android:layout_height="wrap_content"
android:text="-"
android:id="#+id/button7"
android:layout_alignTop="#+id/button"
android:layout_toLeftOf="#+id/editText2"
android:layout_toStartOf="#+id/editText2"
android:background="#ffff45df"
android:textSize="24dp" />
<Button
android:layout_width="30dp"
android:layout_height="wrap_content"
android:text="+"
android:id="#+id/button8"
android:background="#ffff45df"
android:textSize="24dp"
android:layout_alignTop="#+id/button2"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="30dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/editText3"
android:layout_toStartOf="#+id/button8"
android:text=" 0"
android:textSize="24dp"
android:background="#FFFFFF"
android:layout_alignTop="#+id/button2"
android:layout_toLeftOf="#+id/button8" />
<EditText
android:layout_width="30dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/editText4"
android:layout_toStartOf="#+id/button8"
android:text=" 0"
android:textSize="24sp"
android:background="#FFFFFF"
android:layout_alignTop="#+id/button2"
android:layout_toLeftOf="#+id/button8"
android:layout_alignBottom="#+id/button8" />
<Button
android:layout_width="30dp"
android:layout_height="wrap_content"
android:text="-"
android:id="#+id/button9"
android:layout_toStartOf="#+id/editText3"
android:background="#ffff45df"
android:textSize="24dp"
android:layout_alignTop="#+id/button2"
android:layout_toLeftOf="#+id/editText3" />
<Button
android:layout_width="30dp"
android:layout_height="wrap_content"
android:text="+"
android:id="#+id/button10"
android:background="#ffff45df"
android:textSize="24dp"
android:layout_alignTop="#+id/button3"
android:layout_alignRight="#+id/button8"
android:layout_alignEnd="#+id/button8" />
<Button
android:layout_width="30dp"
android:layout_height="wrap_content"
android:text="+"
android:id="#+id/button11"
android:background="#ffff45df"
android:textSize="24dp"
android:layout_alignTop="#+id/button4"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="30dp"
android:layout_height="wrap_content"
android:text="+"
android:id="#+id/button12"
android:background="#ffff45df"
android:textSize="24dp"
android:layout_alignTop="#+id/button5"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="30dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/editText5"
android:layout_toStartOf="#+id/button10"
android:text=" 0"
android:textSize="24dp"
android:background="#FFFFFF"
android:layout_alignTop="#+id/button3"
android:layout_toLeftOf="#+id/button10"
android:layout_above="#+id/button4" />
<EditText
android:layout_width="30dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/editText6"
android:layout_toStartOf="#+id/button11"
android:text=" 0"
android:textSize="24dp"
android:background="#FFFFFF"
android:layout_alignTop="#+id/button4"
android:layout_toLeftOf="#+id/button11"
android:layout_alignBottom="#+id/button11" />
<EditText
android:layout_width="30dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/editText7"
android:layout_toStartOf="#+id/button12"
android:text=" 0"
android:textSize="24dp"
android:background="#FFFFFF"
android:layout_alignTop="#+id/button5"
android:layout_toLeftOf="#+id/button12"
android:layout_alignBottom="#+id/button12" />
<Button
android:layout_width="30dp"
android:layout_height="wrap_content"
android:text="-"
android:id="#+id/button14"
android:layout_toStartOf="#+id/editText6"
android:background="#ffff45df"
android:textSize="24sp"
android:layout_alignTop="#+id/button4"
android:layout_toLeftOf="#+id/editText6" />
<Button
android:layout_width="30dp"
android:layout_height="wrap_content"
android:text="-"
android:id="#+id/button15"
android:layout_toStartOf="#+id/editText7"
android:background="#ffff45df"
android:textSize="24sp"
android:layout_alignTop="#+id/button5"
android:layout_toLeftOf="#+id/editText7" />
<Button
android:layout_width="30dp"
android:layout_height="wrap_content"
android:text="-"
android:id="#+id/button16"
android:layout_toStartOf="#+id/editText5"
android:background="#ffff45df"
android:textSize="24sp"
android:layout_alignTop="#+id/button3"
android:layout_toLeftOf="#+id/editText5" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText8"
android:text="Total:"
android:background="#FFFFFF"
android:textSize="24sp"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#+id/textView"
android:layout_toStartOf="#+id/textView" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/editText9"
android:layout_alignBottom="#+id/editText8"
android:layout_toLeftOf="#+id/textView2"
android:layout_toStartOf="#+id/textView2"
android:layout_alignLeft="#+id/textView"
android:layout_alignStart="#+id/textView"
android:text=" $ 0.00"
android:background="#FFFFFF"
android:textSize="24sp"
android:layout_alignTop="#+id/editText8" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Order"
android:id="#+id/orderbtn"
android:textSize="24sp"
android:background="#drawable/buttonround"
android:layout_alignBottom="#+id/editText9"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button7"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="$3.00 per drink"
android:textColor="#000000"
android:textSize="20sp"/>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button9"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="$3.00 per drink"
android:textColor="#000000"
android:textSize="20sp" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button16"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="$3.00 per drink"
android:textColor="#000000"
android:textSize="20sp"/>
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button14"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="$3.00 per drink"
android:textColor="#000000"
android:textSize="20sp"/>
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button15"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="$3.00 per drink"
android:textColor="#000000"
android:textSize="20sp"/>
</RelativeLayout>
java code:
package com.example.cofeeshop;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class DrinkMenu extends Activity {
Button button;
Button buttton6; Button buttton7; Button buttton8; Button buttton9;
Button buttton10; Button buttton11; Button buttton16; Button buttton14;
Button buttton12; Button buttton15;
// EditText editText2; EditText editText4; EditText editText5;
// EditText editText6; EditText editText7; EditText editText9;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.drinkmenu);
addListenerOnButton();
}
private void addListenerOnButton() {
final Context context = this;
button = (Button) findViewById(R.id.orderbtn);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(context, ThirdPartyPaymentMethod.class);
startActivity(intent);
}
});
}
}
I already have my manifest to allow button actions.
I know there are methods out there, but my searches have ended in my frustration. Any help would be appreciated. I am new to this, I enjoy the front end, but the back end is new.
I'll do a part and for remaining you have to do.
Consider,
- is a button with id 'button1' and '+' has button2
Quantity is a EditText which has id qty.
Right, coming to the code :
public class MainActivity extends Activity {
EditText quantity;
Button plus,minus;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
plus = (Button) findViewById(R.id.button1);
minus = (Button) findViewById(R.id.button2);
quantity = (EditText) findViewById(R.id.qty);
plus.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
String numb = quantity.getText().toString();
int num1 = Integer.parseInt(numb);
int inum = num1+1;
quantity.setText(Integer.toString(inum));
}
});
minus.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
String numb = quantity.getText().toString();
int num1 = Integer.parseInt(numb);
int inum = num1-1;
quantity.setText(Integer.toString(inum));
}
});
}
}
For sub total, you just need to multiply quantity and the item price. For the Total Price, you just need to add all the subtotals. Hope it helps!
UPDATE about Catching Zero:
You are getting the quantity here.
String numb = quantity.getText().toString();
int num1 = Integer.parseInt(numb);
So, if the number is 0, perform if else
if (num1==0)
{
//Create a alert showing your quantity is zero.
//here i use toast to display
Toast.makeText(this,"Your quantity is Zero. You can't reduce the quantity", Toast.LENGTH_LONG).show();
}
else
{
// do the stuffs here
}
what you want to do is something like this:
Button button = (Button) findViewById(R.id.my_button);
final TextView textView = (TextView) findViewById(R.id.my_text_view);
button.setOnClickListener(new View.OnClickListener() {
#Overrride
public void onClick(View aView) {
textView.setText("Hi");
}
});
You can write this in the onCreate() method of the Activity. Not tested yet, but this will change the text of the TextView to the desired value. Let me know if I have understood your problem correctly.

ListView row not clickable (after adding two buttons)

Strangely, my listView's onClick no longer works after I added two Buttons: Submit and Show Result.
Here is the list view xml.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".CulturalActivity"
android:background="#EFEFEF"
android:id="#+id/AdLayout"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="3dp"
>
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:divider="#android:color/transparent"
android:descendantFocusability="blocksDescendants"
android:scrollbars="none"
android:dividerHeight="10dp"
android:listSelector="#drawable/list_selector" />
</RelativeLayout>
Here is the layout of each list row:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="315dp"
android:clickable="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="7dp"
android:background="#drawable/bg_card"
android:orientation="horizontal"
android:padding="5dip" >
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginLeft="-60dp"
android:background="#2093CD"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="52dp"
android:text="Audit"
android:textColor="#android:color/white"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/relativeLayout2" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Farm/Grp"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_alignTop="#+id/tile"
android:layout_toRightOf="#+id/textView4" />
<!--thumbnail-->
<LinearLayout
android:layout_width="80dp"
android:layout_height="80dp"
android:background="#drawable/thumbnail_image"
android:layout_marginTop="35dp"
android:gravity="center"
android:id="#+id/tile">
<ImageView
android:id="#+id/thumbImage"
android:layout_width="50dp"
android:clickable="false"
android:layout_height="50dp"
android:src="#drawable/opened" />
</LinearLayout>
<TextView
android:id="#+id/crophead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Crop"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_alignBottom="#+id/tile"
android:layout_alignLeft="#+id/title" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Certification"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:layout_below="#+id/textView4"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+id/certification"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/textView2"
android:layout_marginLeft="22dp"
android:layout_toRightOf="#+id/title"
android:text="Test"
android:textColor="#343434"
android:textSize="17sp" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Audit Type"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_below="#+id/tile"
android:layout_alignLeft="#+id/textView2"
android:layout_marginTop="20dp" />
<TextView
android:id="#+id/audittype"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/textView2"
android:layout_alignLeft="#+id/certification"
android:maxLines="2"
android:text="ES"
android:textColor="#343434"
android:textSize="17sp" />
<View
android:layout_width="fill_parent"
android:layout_height="3px"
android:layout_marginTop="200dp"
android:background="#21265b"
android:id="#+id/view" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Date"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_below="#+id/view"
android:layout_alignLeft="#+id/view"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_alignParentBottom="false" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="End Date"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_marginRight="15dp"
android:layout_alignTop="#+id/textView6"
android:layout_alignRight="#+id/startdate" />
<TextView
android:id="#+id/startdate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#8B1A1A"
android:text="30/05/1992"
android:textSize="17sp"
android:layout_alignTop="#+id/enddate"
android:layout_toRightOf="#+id/relativeLayout2"
android:layout_marginLeft="6dp"
android:layout_alignParentBottom="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#8B1A1A"
android:text="2/13/14"
android:textSize="17sp"
android:id="#+id/enddate"
android:layout_below="#+id/textView7"
android:layout_alignRight="#+id/textView7" />
<TextView
android:id="#+id/farm"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/audittype"
android:maxLines="3"
android:layout_alignTop="#+id/title"
android:text="Tea Estate Nagarcoil Tamil Nadu, India "
android:textColor="#343434"
android:textSize="17sp" />
<TextView
android:id="#+id/crop"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/farm"
android:layout_alignTop="#+id/crophead"
android:maxLines="2"
android:text="Wheat without its chaff and barn but not brown"
android:textColor="#343434"
android:textSize="17sp" />
<Button
android:id="#+id/upsync"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#drawable/blue_thumb"
android:layout_below="#+id/enddate"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Show Results"
android:textColor="#android:color/white" />
<Button
android:id="#+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#+id/upsync"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_below="#+id/enddate"
android:background="#drawable/blue_thumb"
android:text="Submit"
android:textColor="#android:color/white" />
</RelativeLayout>
Here is the click snippet of the list view:
listview.setOnItemClickListener( new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View view,
int position, long id) {
long audit_id;
try{
audit_id = (new CustomListAdapter(HomeList.this, c).getAuditID(position));
changeTileStatus(audit_id,"opened");
System.out.println("listClicked");
sendAuditAndIntent(audit_id);
}catch(Exception e)
{
System.out.println("ERROR # HOMELIST list onClick: "+e);
}
}
private void sendAuditAndIntent(long audit_id) { //sends audit id and api key
Intent intent = new Intent(HomeList.this,ChapterActivity.class );
Bundle extras= new Bundle();
extras.putString("audit_id",String.valueOf(audit_id));
extras.putString("api_key", api_key);
intent.putExtras(extras);
startActivity(intent);
}
private void changeTileStatus(long audit_id, String value) {
AuditTableManager tile= new AuditTableManager(HomeList.this);
tile.open();
tile.updateEntry(audit_id, value);
tile.close();
}
});
OnItemClickListener is not called if cells contain clickable Views. It is an Android feature. You can handle clicks by OnClickListener then - set it to your two buttons (not the listView itself).
In your adapter:
public View onCreateView(..., final int position){
...
convertView.findViewById(R.id.button1).setOnClickListener(new OnClickListener(){
public void onClick(View view){
itemClickedAction1(position);
}
});
convertView.findViewById(R.id.button2).setOnClickListener(new OnClickListener(){
public void onClick(View view){
itemClickedAction2(position);
}
});
...
}
Try android:Focusable="false" and also android:clickable="false" in the custom row TextView

Categories

Resources