After creating a list view with XML drawables on the side of each list item, for some reason the image views are not appearing the way that was expected. For each item, only a small horizontal line appears at the top of each list item rather than the drawable also filling up the height of each list view item. What needs to be done in order to fix the height of the image?
drawable/ic_red.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size android:width="20dp" />
<solid android:color="#color/red"/>
</shape>
drawable/ic_yellow.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size android:width="20dp" />
<solid android:color="#color/yellow"/>
</shape>
drawable/ic_green.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size android:width="20dp" />
<solid android:color="#color/green"/>
</shape>
fragment_helloworld.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/list_helloworld"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
listitem_helloworld.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="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/item_img"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingStart="5dp"
android:paddingEnd="5dp"/>
<TextView
android:id="#+id/item_colourtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:padding="10dp"
android:layout_toEndOf="#id/item_img"/>
</RelativeLayout>
FragmentHelloWorld.java
public class FragmentHelloWorld extends android.support.v4.app.Fragment {
public FragmentHelloWorld() {
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
View v = inflater.inflate(R.layout.fragment_helloworld, container, false);
// Array of strings for ListView
String[] listviewTitle = new String[]{
"Item 1",
"Item 2",
"Item 3"
};
// Array of images for ListView
int[] listviewImage = new int[]{
R.drawable.ic_red,
R.drawable.ic_yellow,
R.drawable.ic_green
};
List<HashMap<String, String>> aList = new ArrayList<>();
for (int i = 0; i < 3; i++) {
HashMap<String, String> hm = new HashMap<>();
hm.put("listview_title", listviewTitle[i]);
hm.put("listview_image", Integer.toString(listviewImage[i]));
aList.add(hm);
}
String[] from = {"listview_image", "listview_title"};
int[] to = {R.id.item_img, R.id.item_colourtitle};
SimpleAdapter simpleAdapter = new SimpleAdapter(getActivity().getBaseContext(), aList, R.layout.listitem_helloworld, from, to);
ListView list_helloworld = (ListView) v.findViewById(R.id.list_helloworld);
list_helloworld.setAdapter(simpleAdapter);
}
You may want to take a look at this post here
Or you may try specifying a rectangular shape to the drawables and use LinearLayout , that would be simple.
Related
I have a linearLayout with some cardviews. When the Activity is created, these cardViews get an onClickListern. This Activity has a button that can shrink said linearLayout. However, once shrunk the location of the cardViews no longer match where you interact with it. For example, if you have a cardView on the middle, left side of the screen. Than shrink the linearLayout. You have to tap where the cardView would be, as if the linearLayout wasn't shrunk. Trying to tap where the actual cardView is, does nothing. How do I reposition the the location and size of the onClickListner to match the new location of the cardViews? I'm not against changing my approach on how to resize the linearLayout.
Before Shrinking:
After shrinking:
zoom_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter = "true">
<scale
xmlns:android = "http://schemas.android.com/apk/res/android"
android:duration = "1000"
android:fromXScale="1"
android:fromYScale = "1"
android:pivotX = "50%"
android:pivotY = "50%"
android:toXScale = "2"
android:toYScale = "2"/>
</set>
zoom_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter = "true">
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration = "2500"
android:fromXScale = "1"
android:fromYScale = "1"
android:pivotX = "50%"
android:pivotY = "50%"
android:toXScale = ".2"
android:toYScale = ".2" />
</set>
TreeActivity.java
public class TaxaTreeViewActivity extends AppCompatActivity {
private TaxonomyNode taxonomyTree = TaxonomyNodeUtil.getInstance().getTaxonomyTree();
private BaseTreeAdapter adapter;
private Button zoomInButton, zoomOutButton;
private Animation zoomInAnim, zoomOutAnim;
...
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tree_view);
...
adapter = new BaseTreeAdapter<NodeViewHolder>(this, R.layout.node) {...
//Tree stuff}
zoomInAnim = AnimationUtils.loadAnimation(this, R.anim.zoom_in);
zoomOutAnim = AnimationUtils.loadAnimation(this, R.anim.zoom_out);
zoomInButton = findViewById(R.id.treeZoomInButton);
zoomOutButton = findViewById(R.id.treeZoomOutButton);
zoomOutButton.setOnClickListener(v -> {treeView.startAnimation(zoomOutAnim)});
zoomInButton.setOnClickListener(v -> {treeView.startAnimation(zoomInAnim);});
activity_tree_view.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:id="#+id/zoom_linear_layout"
tools:context=".TaxaTreeViewActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/treeZoomOutButton"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:id="#+id/treeviewContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<de.blox.treeview.TreeView
android:id="#+id/treeview"
android:layout_width="match_parent"
android:layout_height="match_parent"></de.blox.treeview.TreeView>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<Button
android:id="#+id/treeZoomInButton"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginBottom="8dp"
android:src="#drawable/ic_zoom_in"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="#+id/treeZoomOutButton"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:src="#drawable/ic_zoom_out"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
I have been trying to make a custom TabLayout indicator like Google Drive's one but didn't figure it out.
I tried the following article:
https://medium.com/#adrianespi94/apply-new-google-style-to-your-android-material-tabs-4d498c993c51
It works fine, but not as good as the one in the GIF below.
Thanks in advance.
There's two thing like this.
works by clicking on tab.
works by horizontal scrolling and clicking on tab also.
I don't know what you want actually. cause, the link you gave that is no 1. which is TabHost. I am adding source code for both.
ViewPagerAdapter :
public class ViewPagerAdapter extends FragmentPagerAdapter {
private final List<Fragment> fragmentList=new ArrayList<>();
private final List<String> fragmentListTitles=new ArrayList<>();
public ViewPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
return fragmentList.get(position);
}
#Override
public int getCount() {
return fragmentListTitles.size();
}
//return page title
#Override
public CharSequence getPageTitle(int position) {
return fragmentListTitles.get(position);
}
public void AddFragment(Fragment fragment,String title)
{
fragmentList.add(fragment);
fragmentListTitles.add(title);
}
}
MainActivity :
private TabLayout tabLayout;
private AppBarLayout appBarLayout;
private ViewPager viewPager;
tabLayout=(TabLayout)findViewById(R.id.tablayout);
viewPager=(ViewPager)findViewById(R.id.viewpager);
//create viewpageradaper class object
ViewPagerAdapter adapter=new ViewPagerAdapter(getSupportFragmentManager());
//adding fragments using adapter object
adapter.AddFragment(new FreeFireFragment(), "Free Fire");
adapter.AddFragment(new PubgFragment(), "Pubg");
adapter.AddFragment(new CallOfDutyFragment(), "Call of Duty");
//set adapter into viewpager
viewPager.setAdapter(adapter);
//set viewpager into tablayout
tabLayout.setupWithViewPager(viewPager);
If you want to add icon :
//for set icon into tab items
final int[] ICONS = new int[]{
R.drawable.ff,
R.drawable.pubg,
R.drawable.cod
};
//enter the following source code below the MainActivity source code
//set icon to tab items
tabLayout.getTabAt(0).setIcon(ICONS[0]);
tabLayout.getTabAt(1).setIcon(ICONS[1]);
tabLayout.getTabAt(2).setIcon(ICONS[2]);
activity_home.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">
<com.google.android.material.tabs.TabLayout
android:id="#+id/tablayout"
android:layout_width="match_parent"
android:layout_height="55dp"
app:tabBackground="#color/homeColor"
app:tabGravity="fill"
app:tabIndicatorColor="#color/tabIndicator"
app:tabMode="fixed"
app:tabSelectedTextColor="#color/tabIndicator"
app:tabTextColor="#color/tabTextColor">
</com.google.android.material.tabs.TabLayout>
<androidx.viewpager.widget.ViewPager
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/viewpager">
</androidx.viewpager.widget.ViewPager>
</LinearLayout>
Above source code works as no 2.
Now, no 1:
Layout :
<TabHost
android:id="#+id/tab_host"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/rl_">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/Filters"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
layout="#layout/filters_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="#+id/Adjustments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
layout="#layout/adjustment_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#40cccccc" />
</LinearLayout>
</TabHost>
MainActivity
//setup tabHost
TabHost tabHost = findViewById(R.id.tab_host);
tabHost.setup();
//set item 1 in tabhost
TabHost.TabSpec Filters= tabHost.newTabSpec("Filters");
Filters.setContent(R.id.Filters);
Filters.setIndicator("Filters");
tabHost.addTab(Filters);
//set item 2 in tabhost
TabHost.TabSpec Adjustments= tabHost.newTabSpec("Adjustments");
Adjustments.setContent(R.id.Adjustments);
Adjustments.setIndicator("Adjustments");
tabHost.addTab(Adjustments);
I made the solution by myself, it seems like the solution can be done easily without libraries or any spaghetti code.
First, you need to an XML file for tab indicator:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:bottomLeftRadius="0dp"
android:bottomRightRadius="0dp"
android:topLeftRadius="8dp"
android:topRightRadius="8dp" />
<size android:height="3dp" />
<solid android:color="#color/selectedColor" />
</shape>
Then make a Selector to change the indicator color based on your selection:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/selectedColor" android:state_selected="true" />
<item android:color="#color/notSelectedColor" />
</selector>
Finally in your TabLayout, add these lines:
<com.google.android.material.tabs.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabIconTint="#drawable/tab_selector_color" //for selection
app:tabIndicator="#drawable/tab_indicator" //for rounded corners
app:tabIndicatorAnimationMode="elastic" //for that elastic swiping effect
app:tabIndicatorColor="#color/selectedColor"
app:tabIndicatorFullWidth="false"
app:tabInlineLabel="true"
app:tabSelectedTextColor="#color/selectedColor"
app:tabTextColor="#color/notSelectedColor"/>
I would like to programatically style my dynamically created checkboxes as radio buttons as I prefer the look.
To do this I have created a checkboxStyle.xml and put it in values section of the res folder.
checkboxStyle.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="checkboxStyle">
<item name="android:checkboxStyle">#android:style/Widget.DeviceDefault.Light.CompoundButton.RadioButton</item>
</style>
</resources>
I am then calling this in my fragment as I create my checkboxes but R.id.checkboxStyle is coming up as not found, not really sure where to put this id though or if I need to refer to it in another way
CheckBox checkBox;
ArrayList<String> list = new ArrayList<>();
list.add("test");
list.add("this");
list.add("thing");
final ArrayList<CheckBox> checkBoxArray = new ArrayList<>();
for(int i = 0; i < list.size(); i++){
checkBox = new CheckBox(getActivity(), null, R.id.checkboxStyle);
checkBox.setId(i);
checkBox.setText(list.get(i));
checkBox.setTag(list.get(i));
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
Log.v("CheckBox - checked", buttonView.getTag().toString());
}else{
Log.v("CheckBox - unchecked", buttonView.getTag().toString());
}
}
});
checkBoxArray.add(checkBox);
checkboxContainer.addView(checkBox);
}
testing_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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/colorWhite">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/checks"
android:orientation="vertical">
</LinearLayout>
<Button
android:id="#+id/saveBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:text="Save"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>
checkBox = new CheckBox(getActivity(), null, R.id.checkboxStyle);
it's not an id, it's an style and you need to access it like this
R.style.checkboxStyle;
I have a ListView of values and I want to make each value editable by pressing on it and opening a context menu. How can I add an EditText field to the context menu that appears when clicking on an item in a ListView? If you have a better idea for said issue, feel free to suggest it. Thanks in advance to anyone who answers!
You don't have to use a context menu for that. You can use AlertDialog.
Check out this answer here.
https://stackoverflow.com/a/45352961/8200290
Just create a different layout with an edit view.
Here is you solution.
You are going to have to edit things to make it fit into your application!
MainActivity class
public class MainActivity extends AppCompatActivity {
List<String> list = new ArrayList<String>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list.add("Android");
list.add("iPhone");
list.add("Windows");
list.add("Blackberry");
list.add("Mac");
list.add("Laptop");
list.add("LCD");
list.add("Dell");
ArrayAdapter adapter = new ArrayAdapter<String>(MainActivity.this, R.layout.list_view_item, list);
ListView listView = (ListView) findViewById(R.id.mobile_list);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(MainActivity.this, "Clicked: " + list.get(position), Toast.LENGTH_SHORT).show();
AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);
View alertView = getLayoutInflater().inflate(R.layout.custom_alert, null);
//Set the view
alert.setView(alertView);
//Show alert
final AlertDialog alertDialog = alert.show();
//Can not close the alert by touching outside.
alertDialog.setCancelable(false);
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//Set the edit text for the item clicked
EditText editText = (EditText) alertView.findViewById(R.id.editText);
editText.setText(list.get(position));
ImageView closeButton = (ImageView) alertView.findViewById(R.id.closeButton);
closeButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
alertDialog.dismiss();
}
});
}
});
listView.setAdapter(adapter);
}
}
activity_main.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"
tools:context="com.vzw.www.listviewalert.MainActivity">
<ListView
android:id="#+id/mobile_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
list_view_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/label"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:textSize="16dip"
android:textStyle="bold" >
</TextView>
custom_alert.xml
-> This will show your EDIT text. The box at the bottom closes the alert
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/alertContainer"
android:background="#drawable/custom_alert_bg">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/rowOne">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText"/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</RelativeLayout>
<ImageView
android:id="#+id/closeButton"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_weight="0.33"
android:background="#cdcdcd" />
</RelativeLayout>
#drawable/custom_alert_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="#ffffff"/>
<corners
android:radius="5dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
You get the following:
I use following java code to run this,
public class MainActivity extends ActionBarActivity {
int transitionTime = 300;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TransitionDrawable transition = (TransitionDrawable) findViewById(R.id.relativeLayoutMain).getBackground();
transition.startTransition(transitionTime);
}
Please help me to sole this problem.
Hi I'm new to android and what I'm try to do is change layout background color continuously.
Above method trigger error to me, I not found solution to this but I use different approach to do this.
I use timer with TransitionDrawable and here is my working copy of code.
Here I add "drawable" resources,
transition_drawable.xml (this is main resource xml set this resource file to your layer backbround)
<?xml version="1.0" encoding="UTF-8"?>
<transition xmlns:android="http://schemas.android.com/apk/res/android">
<!-- The drawables used here can be solid colors, gradients, shapes, images, etc. -->
<item android:drawable="#drawable/color_selector_01" />
<item android:drawable="#drawable/color_selector_02" />
</transition>
color_selector_01.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:angle="90"
android:startColor="#919bfa"
android:endColor="#4e5bda"
android:type="linear" />
</shape>
</item>
</selector>
color_selector_02.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:angle="90"
android:startColor="#fe5528"
android:endColor="#3c1ed4"
android:type="linear" />
</shape>
</item>
</selector>
In my main layout I set layer background to "transition_drawable"
here is my "activity_main.xml"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:background="#drawable/transition_drawable" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="#+id/linkTerms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:singleLine="true"
android:text="#string/linkTerms" />
<TextView
android:id="#+id/and"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="#string/and" />
<TextView
android:id="#+id/linkPrivacy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:text="#string/linkPrivacy" />
</LinearLayout>
</ScrollView>
Finlay here is my MainActivity.java file
#TargetApi(Build.VERSION_CODES.HONEYCOMB) #SuppressLint("NewApi") public class MainActivity extends ActionBarActivity {
int transitionTime = 6000;
private RelativeLayout Rlayout;
private TransitionDrawable trans;
final Handler handler_interact=new Handler();//not defined as final variable. may cause problem
View layout_interact;
#SuppressLint("NewApi") #Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
layout_interact =(View) findViewById(R.id.relativeLayoutMain);
Rlayout = (RelativeLayout)findViewById(R.id.relativeLayoutMain);
Resources res = this.getResources();
trans = (TransitionDrawable)res.getDrawable(R.drawable.transition_drawable);
Rlayout.setBackgroundDrawable(trans);
BackgroundColoerChangerCallTimer();
}
public void BackgroundColoerChangerCallTimer(){
//creating timer
Timer timer_interact=new Timer();
timer_interact.schedule(new TimerTask() {
#Override
public void run() {
UpdateGUI();
}
}, 3000);
}
private void UpdateGUI() {
handler_interact.post(runnable_interact);
}
//creating runnable
final Runnable runnable_interact = new Runnable() {
public void run() {
//ayout_interact.setBackgroundColor(Color.GREEN);
trans.reverseTransition(transitionTime);
BackgroundColoerChangerCallTimer();
}
};