Reputation: 1623
This is a general question. I could not get any answer for this on the Google, so asking on the stackoverflow.
Some of the android apps have cart button at the top of the activity(action bar).
For example I have attached an image of amazon android application.
All the products would be listed through webview
and when the user places order on amazon an order cart updates with the number from 0 to 1 which is in action bar.
This updation is happening in android from webview
to some widget used in android most probably.
Could anyone let us know how this could be achieved or totally the whole activity itself is webview
? I want to know what widget are they using and how are they updating the cart in the activity.
Any pointers to examples would be really helpful.
Attached is the image of amazon android application screen.
thanks.
Upvotes: 1
Views: 5900
Reputation: 157457
inside your res/menu/menuitem.xml you can define the following option:
android:actionLayout="@layout/yourcustomlayout"
where yourcustomlayout could be
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:src="@drawable/cart" />
<TextView
android:visibility="invisible"
android:id="@+id/tv"
style="@style/DefaultTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|top"
android:background="@drawable/mybackground" />
inside onCreateOptionsMenu you can take the references to your textview as follow:
private TextView cartTV;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.virtual_betting, menu);
MenuItem item = menu.getItem(0);
cartTV = (TextView) item.getActionView().findViewById(R.id.pallino);
return true;
}
and update when you need to update
Upvotes: 0
Reputation: 16043
I don't know if the standard action bar items can be updated on runtime.
However, the action bar supports the ability to add a custom layout to it. In this case I don't see any difficulties in setting a listener when an item is added to the cart, and reflect this on UI by updating that custom layout.
UPDATED:
To add a custom layout, from the code:
ActionBar bar = getActionBar();
bar.setCustomView(R.layout.custom_action_bar);
or from the styles:
<style name="ActionBar" parent="android:style/Widget.Holo.Light.ActionBar">
.....
<item name="android:customNavigationLayout">@layout/custom_action_bar</item>
</style>
Now, in your R.layout.custom_action_bar
you'll have that button with a number above representing the number of items in the cart. Obviously that number should be a TextView
, that will be incremented every time an item is added to the cart.
For this you will need a listener in your activity, that will update that TextView, for example:
@Override
public void onItemAdded(){
cart.setText(CURRENT_NUMBER_OF_ITEMS_IN_CART);
}
Upvotes: 1
Reputation: 2716
This might help you, this may not be a proper answer to the question.
I think you can do it using WebViewClient
and onPageFinished
. Watch for a specic pattern of URL. If the pattern matches you can perform the action u needed.
One more method, think about this too,
Let the app send request to the server to update the cart. The app will frequently send request to the server to check for cart update.
:)
Upvotes: 0
Reputation: 8028
they use action bar, action bar is window feather that display on top bar, for more info and example of this you can see the source code for google I/O app here
Upvotes: 0