android - add blink to customized listview Item? -
i have created listview
contains multiple items, , added border items this:
because of customized border original blink of item blocked doesn't appear, , i've tried add blink through animation there delay , work on main thread, used animation inside threads same delay thing, force me forget animation there anyway can make item blink when clicked without using animation or using in efficient way , way used blink animation inside onitemclicklistener
can find in code below: onitemclicklistener
handle blink:
datalist.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> arg0, final view arg1, final int arg2, long arg3) { // todo auto-generated method stub tvwarningnoemp.setvisibility(view.gone); // adding blink final animation animation = new alphaanimation( 1, 0); // change // alpha // // // visible // // invisible animation.setduration(100); // duration - half // second animation .setinterpolator(new linearinterpolator()); // // not // alter // animation // rate animation.setrepeatcount(animation.infinite); // repeat // animation // infinitely animation.setrepeatmode(animation.reverse); arg1.startanimation(animation); // blink 1 time timer new countdowntimer(100, 100) {// countdowntimer(edittext1.gettext()+edittext2.gettext()) // parse long public void ontick(long millisuntilfinished) { // here can have logic set text // edittext } public void onfinish() { arg1.clearanimation(); } }.start(); // set margins tickets buttons linearlayout.layoutparams params = new linearlayout.layoutparams( layoutparams.wrap_content, layoutparams.wrap_content); params.setmargins(0, 0, 30, 0); bassign.setlayoutparams(params); linearlayout.layoutparams paramso = new linearlayout.layoutparams( layoutparams.wrap_content, layoutparams.wrap_content); paramso.setmargins(110, 0, 0, 0); bempchat.setlayoutparams(paramso); noemplayout.setvisibility(linearlayout.gone); emplayout.setvisibility(linearlayout.visible); employee item = adapter.getitem(arg2); ivempicon.setbackgroundresource(r.drawable.free); tvempname.settext(" " + item.getempname()); tvempdetails.settext(" " + item.getempdetails()); emplongitude = item.getemplongitude(); emplatitude = item.getemplatitude(); cameraposition cameraposition = new cameraposition.builder() .target(new latlng(emplatitude, emplongitude)) .zoom(15).build(); googleempmap.animatecamera(cameraupdatefactory .newcameraposition(cameraposition)); markeroptions marker = new markeroptions().position( new latlng(emplatitude, emplongitude)).title( tvempname.gettext().tostring()); marker.icon(bitmapdescriptorfactory .defaultmarker(bitmapdescriptorfactory.hue_red)); googleempmap.addmarker(marker); // based on item add info intent // hide button directions bempdirections.setvisibility(view.gone); // current address geocoder geocoder; list<address> addresses; geocoder = new geocoder(getapplicationcontext(), locale .getdefault()); try { addresses = geocoder.getfromlocation(emplatitude, emplongitude, 1); string street = addresses.get(0).getaddressline(0); string state = addresses.get(0).getadminarea(); string country = addresses.get(0).getcountryname(); tvempcurrentadd.settext(" " + country + "-" + state + "-" + street + " st."); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace();} } });
listview layout:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/redborder" > <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" > <button android:id="@+id/btnback" android:layout_width="30dp" android:layout_height="30dp" android:layout_marginleft="10dp" android:layout_margintop="5dp" android:background="@drawable/back" /> <textview android:id="@+id/tvwarningnoemp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="choose employee here assign problem to!" android:textcolor="#ff0000" android:layout_marginleft="400dp" android:visibility="gone"/> </linearlayout> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginbottom="40dp" android:layout_marginleft="10dp" android:layout_marginright="10dp" android:layout_margintop="10dp" android:layout_weight="2" android:background="@drawable/pepsiborder" android:orientation="vertical" > <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginleft="10dp" android:layout_marginright="10dp" android:layout_margintop="10dp" android:background="@drawable/blueborder" android:orientation="horizontal" android:padding="10dp" > <imageview android:id="@+id/ticketicon" android:layout_width="60dp" android:layout_height="60dp" android:layout_gravity="center_vertical" android:layout_weight="0.1" /> <linearlayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="0.7" android:gravity="center_vertical" android:orientation="vertical" > <textview android:id="@+id/ticketcat" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginleft="7dp" android:gravity="center_vertical" android:textcolor="#d3d9ff" android:textsize="17sp" /> </linearlayout> </linearlayout> <fragment android:id="@+id/ticketmap" android:name="com.google.android.gms.maps.mapfragment" android:layout_width="match_parent" android:layout_height="200dp" android:layout_marginbottom="10dp" android:layout_marginleft="10dp" android:layout_marginright="10dp" android:layout_margintop="10dp" /> <scrollview android:layout_width="wrap_content" android:layout_height="wrap_content" > <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginbottom="10dp" android:layout_marginleft="10dp" android:layout_marginright="10dp" android:orientation="vertical" > <linearlayout android:layout_width="wrap_content" android:layout_height="wrap_content" > <textview android:id="@+id/textview2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="state:" android:textappearance="?android:attr/textappearancemedium" android:textcolor="#d3d9ff" /> <textview android:id="@+id/ticketstate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:textcolor="#d3d9ff" /> </linearlayout> <linearlayout android:layout_width="wrap_content" android:layout_height="wrap_content" > <textview android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="ticket no:" android:textappearance="?android:attr/textappearancemedium" android:textcolor="#d3d9ff" /> <textview android:id="@+id/ticketno" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:textcolor="#d3d9ff" /> </linearlayout> <linearlayout android:layout_width="wrap_content" android:layout_height="wrap_content" > <textview android:id="@+id/textview12" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="report date:" android:textappearance="?android:attr/textappearancemedium" android:textcolor="#d3d9ff" /> <textview android:id="@+id/ticketreportdate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:textcolor="#d3d9ff" /> </linearlayout> <textview android:id="@+id/textview13" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="details:" android:textappearance="?android:attr/textappearancemedium" android:textcolor="#d3d9ff" /> <textview android:id="@+id/ticketdetails" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:textcolor="#d3d9ff" /> </linearlayout> </scrollview> <linearlayout android:id="@+id/llbtn" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:layout_marginbottom="10dp" android:layout_margintop="170dp" android:layout_marginleft="10dp" android:layout_marginright="10dp" android:background="@drawable/blueborder" android:orientation="horizontal" android:padding="10dp" > <button android:id="@+id/btnticketdirections" android:layout_width="match_parent" android:layout_height="30dp" android:layout_weight="1" android:background="@drawable/directions" /> <button android:id="@+id/btnsolve" android:layout_width="match_parent" android:layout_height="30dp" android:layout_weight="1" android:background="@drawable/solve" /> <button android:id="@+id/btnother" android:layout_width="match_parent" android:layout_height="30dp" android:layout_weight="1" android:background="@drawable/other" /> </linearlayout> </linearlayout> <linearlayout android:id="@+id/lllistview" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginbottom="40dp" android:layout_marginleft="10dp" android:layout_marginright="10dp" android:layout_margintop="10dp" android:layout_weight="2" android:background="@drawable/pepsiborder" android:orientation="vertical" > <textview android:id="@+id/textview124" android:layout_width="match_parent" android:layout_height="wrap_content" android:textcolor="#d3d9ff" android:text="free employees" android:textsize="30sp" android:gravity="left" android:layout_marginleft="10dp" android:layout_margintop="10dp" android:textappearance="?android:attr/textappearancelarge" /> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:layout_marginleft="20dp" > <listview android:id="@+id/listtic" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginright="5dp" android:layout_margintop="20dp" android:divider="@android:color/transparent" android:dividerheight="10dp" > </listview> </linearlayout> </linearlayout> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginbottom="10dp" android:layout_marginleft="10dp" android:layout_marginright="10dp" android:layout_margintop="10dp" android:layout_weight="2" android:id="@+id/noemplayout" android:background="@android:color/transparent" android:orientation="vertical" > <textview android:text="please select free employee handle problem!" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:layout_margintop="300dp" /> </linearlayout> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginbottom="40dp" android:layout_marginleft="10dp" android:layout_marginright="10dp" android:layout_margintop="10dp" android:layout_weight="2" android:id="@+id/emplayout" android:background="@drawable/pepsiborder" android:orientation="vertical" > <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginleft="10dp" android:layout_marginright="10dp" android:layout_margintop="10dp" android:background="@drawable/blueborder" android:orientation="horizontal" android:padding="10dp" > <imageview android:id="@+id/empicon" android:layout_width="60dp" android:layout_height="60dp" android:layout_gravity="center_vertical" android:layout_weight="0.1" /> <linearlayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="0.7" android:gravity="center_vertical" android:orientation="vertical" > <textview android:id="@+id/empname" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginleft="7dp" android:gravity="center_vertical" android:textcolor="#d3d9ff" android:textsize="17sp" /> </linearlayout> </linearlayout> <fragment android:id="@+id/empmap" android:name="com.google.android.gms.maps.mapfragment" android:layout_width="match_parent" android:layout_height="200dp" android:layout_marginbottom="10dp" android:layout_marginleft="10dp" android:layout_marginright="10dp" android:layout_margintop="10dp" /> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginbottom="10dp" android:layout_marginleft="10dp" android:layout_marginright="10dp" android:orientation="vertical" > <linearlayout android:layout_width="wrap_content" android:layout_height="wrap_content" > <textview android:id="@+id/textview33" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="current address:" android:textappearance="?android:attr/textappearancemedium" android:textcolor="#d3d9ff" /> <textview android:id="@+id/empaddress" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:textcolor="#d3d9ff" /> </linearlayout> <linearlayout android:layout_width="wrap_content" android:layout_height="wrap_content" > <textview android:id="@+id/textview22" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="details:" android:textappearance="?android:attr/textappearancemedium" android:textcolor="#d3d9ff" /> <textview android:id="@+id/empdetails" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:textcolor="#d3d9ff" /> </linearlayout> </linearlayout> <linearlayout android:id="@+id/llbtn2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:layout_margintop="220dp" android:layout_marginbottom="10dp" android:layout_marginleft="10dp" android:layout_marginright="10dp" android:background="@drawable/blueborder" android:orientation="horizontal" android:padding="10dp" > <button android:id="@+id/btnempdirections" android:layout_width="30dp" android:layout_height="30dp" android:layout_weight="1" android:layout_gravity="center" android:background="@drawable/directions" /> <button android:id="@+id/btnempchat" android:layout_width="30dp" android:layout_height="30dp" android:layout_weight="1" android:layout_gravity="center" android:background="@drawable/chat" /> <button android:id="@+id/btnempassign" android:layout_width="30dp" android:layout_height="30dp" android:layout_weight="1" android:layout_gravity="center" android:background="@drawable/assign" /> </linearlayout> </linearlayout> </linearlayout> </linearlayout> </linearlayout>
listview item layout:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="280dp" android:layout_height="90dp" android:orientation="horizontal" android:background="@drawable/border" android:layout_margintop="10dp" android:padding="10dp" > <imageview android:id="@+id/imgicon" android:layout_width="60dp" android:layout_height="60dp" android:layout_weight="0.1" android:gravity="center_vertical" /> <linearlayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:layout_weight="0.7" android:gravity="center_vertical" > <textview android:id="@+id/txttitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_vertical" android:textsize="17sp" android:textcolor="#d3d9ff" android:layout_gravity="center_vertical" android:layout_marginleft="7dp" /> <textview android:id="@+id/txttitle1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_vertical" android:layout_gravity="center_vertical" android:textsize="13sp" android:textcolor="#d3d9ff" android:layout_marginleft="7dp" /> </linearlayout> </linearlayout>
border.xml:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <stroke android:width="2dip" android:color="#8d8d8d" /> <corners android:radius="10dip"/> <solid android:color="#464a4f" /> </shape>
any appreciated.
if want view blink:
public void blink(final view v) { v.setbackgroundcolor(color.dkgray); v.animate().setduration(25).alpha(0).withendaction(new runnable() { @override public void run() { v.setbackgroundresource(r.drawable.standard_key_normal); v.setalpha(1); } }); }
send view function, replace background whatever drawable or color resource want. if want multiple blinks put in loop.
Comments
Post a Comment