I am really stuck on this. I am trying to do a simple textswitcher which will increment a quantity and update a price based on the quantity. Right now in my xml i have something like a TextView within a TextSwitcher just to increment the quantity. I get the textview with findViewById(R.id.quantity)
.
so this is what i have to find to setup the increment quantity ( I am implemementing ViewFactory)
switcher = (TextSwitcher) findViewById(R.id.switcher);
switcher.setFactory(this);
quantity = (TextView) findViewById(R.id.quantity);
I am also overriding the makeView()
@Override
public View makeView() {
return quantity;
}
Also when an increment button is pressed i increment the counter and set the text on the switcher to the current count. Like this:
switcher.setText(String.valueOf(currentQuantity));
Can someone let me know what I am doing wrong?? I keep getting my nullpointer at this line:
switcher.setFactory(this);
Here is the XML snippet:
<TextSwitcher android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/switcher">
<TextView android:text="TextView" android:id="@+id/quantity" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</TextSwitcher>
From the Documentation for TextSwitcher:
setText (CharSequence text) Sets the text of the next view and switches to the next view. This can be used to animate the old text out and animate the next text in.
Which means you will need at least two text views, one with the old text, and one to receive the new text and animate in. The following XML should work:
<TextSwitcher
android:id="@+id/counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</TextSwitcher>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With