Load images from tableLayout android - java

I have five rows imageView, but this code load only 4 rows? why?
Java code
tl = (TableLayout) findViewById(R.id.tableLayout);
for (int i = 0; i < tl.getChildCount(); i++) {
View v = tl.getChildAt(i);
if (v instanceof TableRow) {
for (int j = 0; j < ((TableRow) v).getChildCount(); j++) {
View innerView = ((TableRow) v).getChildAt(j);
if (innerView instanceof ImageView) {
imageList.add((ImageView) innerView);
idList.add(innerView.getId());
}
}
}
}
Layout
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="false"
android:layout_alignParentBottom="true"
android:layout_marginBottom="275dp"
android:id="#+id/tableLayout">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView3"
android:layout_column="1"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView2"
android:layout_column="2"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:layout_column="3"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView25"
android:layout_column="5"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView5"
android:layout_column="6"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView13"
android:layout_column="1"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView12"
android:layout_column="2"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView11"
android:layout_column="3"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView10"
android:layout_column="5"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView14"
android:layout_column="6"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView9"
android:layout_column="1"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView8"
android:layout_column="2"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView6"
android:layout_column="3"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView7"
android:layout_column="5"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView4"
android:layout_column="6"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView18"
android:layout_column="1"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView17"
android:layout_column="2"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView16"
android:layout_column="3"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView15"
android:layout_column="5"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView19"
android:layout_column="6"
android:nestedScrollingEnabled="false"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="false">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView23"
android:layout_column="1"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView22"
android:layout_column="2"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView21"
android:layout_column="3"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView20"
android:layout_column="5"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView24"
android:layout_column="6"
android:src="#drawable/blog_dp_5058985_7848593_tr_woda" />
</TableRow>
</TableLayout>

I can comparing two imageView? eg
image.get(1).getdrawable()==image.get(2).getdrawable()?
No, by this way it just comparing whether they are the same object or not. In this case this will be false. But, if you want to compare the images of the imageviews, then you should get theirs bitmap then use sameAs method.
//comapre objects returns false
Log.i("EQ", (imageList.get(0).getDrawable().equals(imageList.get(1).getDrawable())) + "");
Log.i("EQ", imageList.get(0).getDrawable().toString()); //android.graphics.drawable.BitmapDrawable#89c323c
Log.i("EQ", imageList.get(1).getDrawable().toString()); //android.graphics.drawable.BitmapDrawable#837dbc5
BitmapDrawable bitmapDrawable0 = ((BitmapDrawable) imageList.get(0).getDrawable());
Bitmap bitmap0 = bitmapDrawable0 .getBitmap();
BitmapDrawable bitmapDrawable1 = ((BitmapDrawable) imageList.get(1).getDrawable());
Bitmap bitmap1 = bitmapDrawable1 .getBitmap();
//comapre the image returns true
Log.i("EQ2", Boolean.toString(bitmap0.sameAs(bitmap1)));
Where i called toString() it shows that, they are not the same object, although they are holding the same image as sameAs indicating.
Note:
instead of equals() method, "==" operator would do the same, there is no difference

Related

How can I check only one radiobutton in two groups if I have two radiogroups with radiobuttons

I have two horizontal radiogroups with radiobuttons and I want to check only one of the radiobuttons but since they are in different radiogroups it allows the radiobutton from the other group to be checked too!Is there any way that when I check only one radiobutton from both groups?
Here is the code below:
<RadioGroup
android:id="#+id/rgSatisfied"
android:visibility="invisible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout">
<RadioGroup
android:id="#+id/rg1"
android:layout_width="383dp"
android:layout_height="47dp"
android:layout_marginLeft="5dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.515"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout">
<RadioButton
android:id="#+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton" />
<RadioButton
android:id="#+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="RadioButton" />
<RadioButton
android:id="#+id/radioButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="RadioButton" />
</RadioGroup>
<RadioGroup
android:id="#+id/rg2"
android:layout_width="378dp"
android:layout_height="49dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="4dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.515"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/rg1">
<RadioButton
android:id="#+id/radioButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton" />
<RadioButton
android:id="#+id/radioButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="RadioButton" />
<RadioButton
android:id="#+id/other"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="Other" />
</RadioGroup>
</RadioGroup>
<RadioGroup
android:id="#+id/rgSomewhat"
android:visibility="invisible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout">
<RadioGroup
android:id="#+id/rg3"
android:layout_width="383dp"
android:layout_height="47dp"
android:layout_marginLeft="5dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.515"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout">
<RadioButton
android:id="#+id/radioButton7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sample1" />
<RadioButton
android:id="#+id/radioButton8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Sample2" />
<RadioButton
android:id="#+id/radioButton9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="Sample3" />
</RadioGroup>
<RadioGroup
android:id="#+id/rg4"
android:layout_width="378dp"
android:layout_height="49dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="4dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.515"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/rg1">
<RadioButton
android:id="#+id/radioButton10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sample4" />
<RadioButton
android:id="#+id/radioButton11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Sample5" />
<RadioButton
android:id="#+id/other2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="Other" />
</RadioGroup>
</RadioGroup>
<RadioGroup
android:id="#+id/rgDissatisfied"
android:visibility="invisible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout">
<RadioGroup
android:id="#+id/rg5"
android:layout_width="383dp"
android:layout_height="47dp"
android:layout_marginLeft="5dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.515"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout">
<RadioButton
android:id="#+id/radioButton13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton" />
<RadioButton
android:id="#+id/radioButton14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="RadioButton" />
<RadioButton
android:id="#+id/radioButton15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="RadioButton" />
</RadioGroup>
<RadioGroup
android:id="#+id/rg6"
android:layout_width="378dp"
android:layout_height="49dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="4dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.515"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/rg1">
<RadioButton
android:id="#+id/radioButton16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton" />
<RadioButton
android:id="#+id/radioButton17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="RadioButton" />
<RadioButton
android:id="#+id/other3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="Other" />
</RadioGroup>
</RadioGroup>
You can solve your problem by listening to changes to both RadioGroups.
When a RadioButton in one RadioGroup is checked, just un-check all RadioButtons in the second RadioGroup. This is tricky, as the un-checking triggers the listener again, crashing your app. In order to prevent that, you have to add an additional condition: That the RadioButton that triggered the event got checked, not un-checked.
Here's the code:
val groupOne = findViewById<RadioGroup>(R.id.radio_group_one)
val groupTwo = findViewById<RadioGroup>(R.id.radio_group_two)
val checkedChangeListener =
RadioGroup.OnCheckedChangeListener { group, checkedId ->
val checkedButton = group.findViewById<RadioButton>(checkedId)
if (group == groupOne && checkedButton?.isChecked == true) {
groupTwo.clearCheck()
}
if (group == groupTwo && checkedButton?.isChecked == true) {
groupOne.clearCheck()
}
}
groupOne.setOnCheckedChangeListener(checkedChangeListener)
groupTwo.setOnCheckedChangeListener(checkedChangeListener)

How to start code when pressed four Buttons in Android

I want to make pin input with Buttons and TextView in Android.
I have Textview for pin , and 9 Buttons for user to press as digits.
What i want when user press four buttons to change my Textview letter by letter(Button by Button) , and when entered fourth button to start code
Here is image:
Any tips please?
Here is my code:
content_main.xml :
<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:background="#color/white"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.group.digit.razvoj.appointment.MainActivity"
tools:showIn="#layout/app_bar_main">
<LinearLayout
android:id="#+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/pinLayoutMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:orientation="vertical"
android:paddingRight="#dimen/left_margin_pin">
<LinearLayout
android:id="#+id/pinTvLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="#dimen/between_margin"
android:layout_marginTop="#dimen/between_margin"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="#+id/pinTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/pin"
android:textColor="#android:color/black"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/passLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="50dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="#+id/pinEntry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="****"
android:textColor="#android:color/black"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/firstRow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="2dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:id="#+id/b1"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:text="1"
android:textColor="#color/black"
android:textSize="30sp" />
<Button
android:id="#+id/b2"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:text="2"
android:textColor="#color/black"
android:textSize="30sp" />
<Button
android:id="#+id/b3"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:text="3"
android:textColor="#color/black"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/secondRow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="2dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:id="#+id/b4"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:text="4"
android:textColor="#color/black"
android:textSize="30sp" />
<Button
android:id="#+id/b5"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:text="5"
android:textColor="#color/black"
android:textSize="30sp" />
<Button
android:id="#+id/b6"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:text="6"
android:textColor="#color/black"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/sthirdRow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="2dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:id="#+id/b7"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:text="7"
android:textColor="#color/black"
android:textSize="30sp" />
<Button
android:id="#+id/b8"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:text="8"
android:textColor="#color/black"
android:textSize="30sp" />
<Button
android:id="#+id/b9"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:text="9"
android:textColor="#color/black"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/forthow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:text="1"
android:textColor="#color/black"
android:textSize="30sp" />
<Button
android:id="#+id/b0"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:text="0"
android:textColor="#color/black"
android:textSize="30sp" />
<Button
android:id="#+id/bback"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:text="-"
android:textColor="#color/black"
android:textSize="30sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
MainActivity.java:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//init buttons
for (int i = 0; i < MAX_PIN_NUM; i++) {
buttonsPinWidget[i] = (Button) findViewById(buttonsPinId[i]);
}
pinentry = (TextView) findViewById(R.id.pinEntry);
}
You should to use one onClickListener for everyone button with switch case inside of it.
In every case of switch case block your should addor delete (if you have the button for deleting) one character it TextView.
After switch case block check the text length in your TextView. If the length of it equals 4, you can try to authorization or login or other actions.
Sorry for bad English.
Very interesting question first of all.
The only solution I can think of is to create a public method which will always check the length of the textview (which I think should be edittext) and add that method for every button. Once the length of the textview is 4, trigger your code you want.
Let me know if you need some more clarification
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String s=txtView.getText().toString();
if(s.length()<3){
s=s+btn.getText().toString();
txtView.setText(""+s);
}else if(s.length()==3){
s=s+btn.getText().toString();
txtView.setText(""+s);
// write your code
}
}
});

Make table row scroll up and down in some period of time automatically

I have create a list of Currency exchange rate by using table with 6 row.
i want 6 row to have some animation like it running up and down automatically in some period of time so it can make user user more attractive on it.
please give me some example or if you have any idea to make table row animation that make more attractive for user.
Move the scrolled position of your view.
public void scrollBy (int x, int y)
Parameters
x - the amount of pixels to scroll by horizontally
y - the amount of pixels to scroll by vertically
lv.scrollBy(100,100) //....like this
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_margin="0sp"
android:layout_weight="0.03"
android:background="#drawable/gradient">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/logo"
android:layout_marginLeft="50dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="35dp"
android:layout_marginTop="10dp"
android:text="GOLDEN ROYAL EXCHANGE"
android:textColor="#ba8707"
android:textStyle="bold"
android:textSize="16sp"
android:backgroundTintMode="multiply"
android:shadowColor="#030303"
android:phoneNumber="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_margin="1sp"
android:background="#drawable/lineback"
android:layout_weight="0.62">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/myScrollview"
android:scrollbars="none">
<TableLayout
android:id="#+id/table01"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:background="#4042dba8"
android:id="#+id/khmerrow"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:minHeight="145px"
android:layout_marginTop="3dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="3dp"
android:src="#drawable/khmerflages" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="-8dp"
android:text="Khmer Riel 柬币"
android:textColor="#000000"
android:textSize="13sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:text="USD/KHR"
android:textColor="#000000"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="30dp"
android:text="4,200"
android:textColor="#000000"
android:textSize="13sp"
android:textStyle="bold" />
</TableRow>
<TableRow android:background="#4042dba8"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:minHeight="145px"
android:layout_marginTop="2.5sp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="3dp"
android:src="#drawable/thaiflags" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-12dp"
android:layout_gravity="center"
android:text="Thai Baht 泰铢"
android:textColor="#000000"
android:textSize="13sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="25dp"
android:text="USD/THB"
android:textColor="#000000"
android:textSize="12sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="30dp"
android:text="35"
android:textColor="#000000"
android:textSize="13sp"
android:textStyle="bold" />
</TableRow>
<TableRow android:background="#4042dba8"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:minHeight="145px"
android:layout_marginTop="2.5sp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="3dp"
android:src="#drawable/chinaflags" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-3dp"
android:layout_gravity="center"
android:text="China RMB 人民币"
android:textColor="#000000"
android:textSize="13sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="18dp"
android:text="USD/RMB"
android:textColor="#000000"
android:textSize="12sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="30dp"
android:text="6.7"
android:textColor="#000000"
android:textSize="13sp"
android:textStyle="bold" />
</TableRow>
<TableRow android:background="#4042dba8"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:minHeight="145px"
android:layout_marginTop="2.5sp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="3dp"
android:src="#drawable/hongkongflags" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="9dp"
android:layout_gravity="center"
android:text="HongKong Dollar 港币"
android:textColor="#000000"
android:textSize="13sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="8dp"
android:text="USD/HKD"
android:textColor="#000000"
android:textSize="12sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="30dp"
android:text="8.7"
android:textColor="#000000"
android:textSize="13sp"
android:textStyle="bold" />
</TableRow>
<TableRow android:background="#4042dba8"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:minHeight="145px"
android:layout_marginTop="2.5sp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="3dp"
android:src="#drawable/malaysiaflags" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_gravity="center"
android:text="Malaysia MYR 马币"
android:textColor="#000000"
android:textSize="13sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="15dp"
android:text="USD/MYR"
android:textColor="#000000"
android:textSize="12sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="30dp"
android:text="6.6"
android:textColor="#000000"
android:textSize="13sp"
android:textStyle="bold" />
</TableRow>
<TableRow android:background="#4042dba8"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:minHeight="145px"
android:layout_marginTop="2.5sp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="3dp"
android:src="#drawable/singaporeflags" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_gravity="center"
android:text="Singapore SGD 新币"
android:textColor="#000000"
android:textSize="13sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="15dp"
android:text="USD/SGD"
android:textColor="#000000"
android:textSize="12sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="30dp"
android:text="1.6"
android:textColor="#000000"
android:textSize="13sp"
android:textStyle="bold" />
</TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="33dp"
android:layout_marginTop="2.5sp"
android:textColor="#000000"
android:id="#+id/date" />
</TableLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_margin="1sp"
android:background="#dee6d461"
android:layout_weight="0.36">
<ViewFlipper
android:id="#+id/bckgrndViewFlipper1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="#+id/bckgrndImageView8"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
android:src="#drawable/exchange1" />
<ImageView
android:id="#+id/bckgrndImageView7"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
android:src="#drawable/exchange2" />
<ImageView
android:id="#+id/bckgrndImageView6"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
android:src="#drawable/exchange3" />
<ImageView
android:id="#+id/bckgrndImageView5"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
android:src="#drawable/exchange4" />
<ImageView
android:id="#+id/bckgrndImageView4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
android:src="#drawable/exchange5" />
<ImageView
android:id="#+id/bckgrndImageView3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
android:src="#drawable/exchange6" />
</ViewFlipper>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="25dp"
android:background="#drawable/gradient">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/trading"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="Trading Hours .................`enter code here`"
android:textSize="13sp"
android:textColor="#ba8707"/>
</LinearLayout>
</LinearLayout>
public class MainActivity extends AppCompatActivity {
Animation fade_in, fade_out, rowanimation;
ViewFlipper viewFlipper;
ScrollView myView;
TextView date;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewFlipper = (ViewFlipper) this.findViewById(R.id.bckgrndViewFlipper1);
fade_in = AnimationUtils.loadAnimation(this,
android.R.anim.fade_in);
fade_out = AnimationUtils.loadAnimation(this,
android.R.anim.fade_out);
viewFlipper.setInAnimation(fade_in);
viewFlipper.setOutAnimation(fade_out);
viewFlipper.setAutoStart(true);
viewFlipper.setFlipInterval(5000);
viewFlipper.startFlipping();
}
}

Android: onClick event listener doesn't work on linearlayout

I am trying to implement an onclick for the entire layout but it won't work.
Here is my function for my RelativeLayout:
public void updateRange(View v)
{
System.out.println("Hello!");
}
and here is my 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="wrap_content"
tools:context=".MainActivity"
android:background="#ffffffff"
android:id="#+id/xasdf"
android:onClick="updateRange">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/toptab"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Settings"
android:fontFamily="monospace"
android:textAllCaps="false"
android:layout_weight="0.333333"
android:id="#+id/settingsButton"
android:background="#fffdb64b" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Solutions"
android:fontFamily="monospace"
android:textAllCaps="false"
android:layout_weight="0.333333"
android:id="#+id/solutionsButton"
android:background="#fffdb64b" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mode"
android:fontFamily="monospace"
android:textAllCaps="false"
android:layout_weight="0.333333"
android:id="#+id/modeButton"
android:background="#fffdb64b" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/chartlayout"
android:layout_below="#+id/toptab"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:weightSum="1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<EditText
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/textView"
android:layout_weight="0.5"
android:background="#ffffffff"
android:fontFamily="monospace"
android:hint="y = ..." />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Graph"
android:fontFamily="monospace"
android:textAllCaps="false"
android:layout_weight="0.25"
android:id="#+id/button"
android:background="#ffd0d0d0"
android:onClick="drawGraph" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Table"
android:fontFamily="monospace"
android:layout_weight="0.25"
android:textAllCaps="false"
android:id="#+id/button2"
android:background="#ffd0d0d0" />
</LinearLayout>
</RelativeLayout>
Try adding the extra line below to your Relative Layout description:
...
android:onClick="updateRange"
android:clickable="true">

Textview cannot be cast to android.widget.listview

I believe to have the textview, but it cannot be cast to listview error in the following code below:
Essentially I am trying to populate information from Parse into a textfield. This I believe is the part of the code that is problematic.
here it throws a "textview cannot be cast to android.widget.listview"
public void done(List<ParseUser> userlistactivityname, ParseException e) {
if (e == null) {
for (int i = 0; i < userlistactivityname.size(); i++) {
mUserActivityNameRetrieved = (TextView) getActivity().findViewById(R.id.userlistactivityname);
mUserActivityNameRetrieved.setText(userlistactivityname.get(i).get("ActivityName").toString());
}
} else {
//else..
}
}
Below is the XML code
<?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="fill_parent"
android:background="#drawable/blue_bac3"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="70dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/profilePictureresult"
android:layout_marginTop="16dp"
android:alpha="0.7"
android:src="#drawable/left_right" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="70dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/imageView2"
android:alpha="0.7"
android:src="#drawable/left_arrow2" />
<TextView
android:id="#+id/userlistactivityname"
android:layout_width="220dp"
android:layout_height="50dp"
android:cacheColorHint="#android:color/transparent"
android:layout_below="#+id/textView1"
android:layout_toLeftOf="#+id/imageView2"
android:divider="#null" >
</TextView>
<ListView
android:id="#+id/userlistheadline"
android:layout_width="280dp"
android:layout_height="90dp"
android:layout_below="#+id/userlistname"
android:layout_centerHorizontal="true"
android:cacheColorHint="#android:color/transparent"
android:divider="#null"
android:textAlignment="center" >
</ListView>
<com.parse.ParseImageView
android:id="#+id/profilePictureresult"
android:layout_width="132dp"
android:layout_height="120dp"
android:layout_below="#+id/userlistheadline"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
android:alpha="1"
android:background="#drawable/border_image"
android:cropToPadding="true"
android:padding="3dp"
android:scaleType="centerCrop" />
<ListView
android:id="#+id/userlistage"
android:layout_width="80dp"
android:layout_height="50dp"
android:layout_below="#+id/profilePictureresult"
android:layout_centerHorizontal="true"
android:layout_marginTop="9dp"
android:divider="#null" >
</ListView>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/userlistage"
android:layout_centerHorizontal="true"
android:layout_marginTop="7dp"
android:text="Activity Name"
android:textColor="#d2f2a2"
android:textSize="23sp"
android:textStyle="bold" />
<Button
android:id="#+id/btnMatchConfirm"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_below="#+id/userlistactivityname"
android:layout_centerHorizontal="true"
android:layout_marginTop="9dp"
android:alpha="0.7"
android:background="#ADD8E6"
android:text="Confirm"
android:textColor="#000000"
android:textSize="22sp"
android:typeface="serif" />
<TextView
android:id="#+id/userlistname"
android:layout_width="250dp"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="17dp"
android:cacheColorHint="#android:color/transparent"
android:clickable="false"
android:divider="#null"
android:drawSelectorOnTop="false"
android:fadingEdge="vertical|none"
android:fastScrollAlwaysVisible="false"
android:fastScrollEnabled="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:listSelector="#android:color/transparent"
android:scrollbarAlwaysDrawVerticalTrack="false"
android:scrollbars="vertical|none"
android:scrollingCache="false"
android:smoothScrollbar="false"
android:textAlignment="gravity" >
</TextView>
Thanks in advance.
you have used the ID "userlistactivityname" more than once, e.g. you define a textview and give it the id userlistactivityname, but later you also have a button with the same id "userlistactivityname"
<TextView
android:id="#+id/userlistactivityname"
...
android:divider="#null" >
</TextView>
<Button
android:id="#+id/btnMatchConfirm"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_below="#+id/userlistactivityname"
...
android:typeface="serif" />
and maybe you even have another widget defined as "userlistactivityname".
Search all your layouts for "userlistactivityname" and make sure that the id is unique!
When you want a view to be below / above / leftOf another view, you reference the view using the code
#id/view_id
when you want to add a new id to the Android R file, you use the code
#+id/new_view_id
if you use #+id/ all the time, you can create problems in your R file. Try changing all references in your code to make it cleaner, and only using #+id/ when specifying android:id
<Button
android:id="#+id/btnMatchConfirm"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_below="#id/userlistactivityname"
android:layout_centerHorizontal="true"
android:layout_marginTop="9dp"
android:alpha="0.7"
android:background="#ADD8E6"
android:text="Confirm"
android:textColor="#000000"
android:textSize="22sp"
android:typeface="serif" />

Categories

Resources