you're looking for: New How to Create Your Android Favourite Button Using Toggle By Michaelsample2
complete information: New How to Create Your Android Favourite Button Using Toggle By Michaelsample2
Artikel Android, Artikel android 2.2, Artikel android 2.3, Artikel android developer, Artikel android operating system, Artikel android sdk, Artikel android update, Artikel android widgets, Artikel best android apps, Artikel droid, Artikel google android, Artikel google play, Artikel latest android, Artikel what is android,
New How to Create Your Android Favourite Button Using Toggle By Michaelsample2
Want to create your own favourite button in any app? It's pretty simple and learning. Using toggle button you can do so. With a toggle button, one can easily change its appearance between states. Using setChecked() method of toggle button smartly, you can create your button anywhere on your Android phone.
The favorite feature is mostly used when one want to shortlist items in a list. But not only this, you can use this tip anywhere on apps. Using android.widget.Button class you can display a normal button.
You may want to keep your toggle button always ON or OFF by default. Use the following toggle as per your need. Understand toggle button working on the android developer site.
android:textOn=""
android:textOff=""
Now use getView() method and set the tag to denote not-Favorited mode and then set the setChecked to false. Also set onClickListener to it.
You can also use CompoundButton.setChecked() or CompoundButton.toggle() method.
favt.setTag(R.id.color, "white"); // Items which are not clicked yet.
favt.setChecked(false);
favt.setOnClickListener(this);
You can learn how to set selected items red using setChecked method in this article (customizing android buttons using selectors)
if(checkFavorite(current)) // Basic method if the item already exists in the database
{
favt.setChecked(true); // To dispaly different icon if item is already shortlisted.
favt.setTag(R.id.color, "red");
}
If you want to save the state preferences, use these codes
ToggleButton tgbutton;
tgbutton = (ToggleButton) findViewById(R.id.toggleButton);
tgbutton.setOnClickListener(new ToggleButton.OnClickListener() {
public void onClick(View v) {
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
Editor editor = sharedPreferences.edit();
editor.putBoolean("toggleButton", tgbutton.isChecked());
editor.commit();
}
});
Now the trick part, if already favoured item is clicked, it must become un-favorite and vice-versa.
public void onClick(View view) {
// TODO Auto-generated method stub
ToggleButton favt = (ToggleButton) view.findViewById(R.id.toggleButton1);
String color = (String) view.getTag(R.id.color); //Red = Favorited
RowData fav = (RowData) getItem(pos);
if(color.equals("white"))
{
addFavorite(fav);
favt.setTag(R.id.color, "red");
}
else
{
removeFavorite(fav);
favt.setTag(R.id.color, "white");
}
}
Now you must have clear idea to create your own android favorite button. If you want to learn how to create android buttons using SQL professionally, see this great article here.
You can also follow this youtube guide to know how to create an android button from start to finish.
You may also like "Modify Android Lock Screen: Get Rid of Annoying Carrier Logo"
Want an Animated Star like favorite button? See this Github article or android-arsenal site. And if you are an android app developer, you might also like a StackOverflow discussion here.
The favorite feature is mostly used when one want to shortlist items in a list. But not only this, you can use this tip anywhere on apps. Using android.widget.Button class you can display a normal button.
You may want to keep your toggle button always ON or OFF by default. Use the following toggle as per your need. Understand toggle button working on the android developer site.
android:textOn=""
android:textOff=""
Now use getView() method and set the tag to denote not-Favorited mode and then set the setChecked to false. Also set onClickListener to it.
You can also use CompoundButton.setChecked() or CompoundButton.toggle() method.
favt.setTag(R.id.color, "white"); // Items which are not clicked yet.
favt.setChecked(false);
favt.setOnClickListener(this);
You can learn how to set selected items red using setChecked method in this article (customizing android buttons using selectors)
if(checkFavorite(current)) // Basic method if the item already exists in the database
{
favt.setChecked(true); // To dispaly different icon if item is already shortlisted.
favt.setTag(R.id.color, "red");
}
If you want to save the state preferences, use these codes
ToggleButton tgbutton;
tgbutton = (ToggleButton) findViewById(R.id.toggleButton);
tgbutton.setOnClickListener(new ToggleButton.OnClickListener() {
public void onClick(View v) {
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
Editor editor = sharedPreferences.edit();
editor.putBoolean("toggleButton", tgbutton.isChecked());
editor.commit();
}
});
Now the trick part, if already favoured item is clicked, it must become un-favorite and vice-versa.
public void onClick(View view) {
// TODO Auto-generated method stub
ToggleButton favt = (ToggleButton) view.findViewById(R.id.toggleButton1);
String color = (String) view.getTag(R.id.color); //Red = Favorited
RowData fav = (RowData) getItem(pos);
if(color.equals("white"))
{
addFavorite(fav);
favt.setTag(R.id.color, "red");
}
else
{
removeFavorite(fav);
favt.setTag(R.id.color, "white");
}
}
Now you must have clear idea to create your own android favorite button. If you want to learn how to create android buttons using SQL professionally, see this great article here.
You can also follow this youtube guide to know how to create an android button from start to finish.
You may also like "Modify Android Lock Screen: Get Rid of Annoying Carrier Logo"
Want an Animated Star like favorite button? See this Github article or android-arsenal site. And if you are an android app developer, you might also like a StackOverflow discussion here.
Articles New How to Create Your Android Favourite Button Using Toggle By Michaelsample2 we have presented
That's all the information about the New How to Create Your Android Favourite Button Using Toggle By Michaelsample2, hopefully can provide benefits to all of you in finding information latest gadgets, how to care for gadgets, tips and tricks mobile phone.
Thank you for reading the article New How to Create Your Android Favourite Button Using Toggle By Michaelsample2 and its url of this article is https://gamzeozgesaroglu.blogspot.com/2016/06/new-how-to-create-your-android.html o you to bookmark and you can go back if you need :), I hope the article this can be useful for you all.
0 Response to "New How to Create Your Android Favourite Button Using Toggle By Michaelsample2"
Post a Comment