java - Changing color of the border of the background of a list item -


i going through this tutorial , had idea of making when press button, 1 of cards borders changes color.

i looked @ this solution, nothing happens.

here have done:

i have xml in drawable shape (feed_item.xml):

<?xml version="1.0" encoding="utf-8"?>  <layer-list xmlns:android="http://schemas.android.com/apk/res/android">     <!-- bottom 2dp shadow -->     <item>         <shape  android:shape="rectangle">              <solid android:color="#d8d8d8" />             <corners android:radius="7dp" />          </shape>     </item>     <!-- white top color -->     <item android:bottom="3px" android:id="@+id/feedsquare">         <shape             xmlns:android="http://schemas.android.com/apk/res/android"             android:shape="rectangle">             <!-- view background color -->             <solid                 android:color="@color/white" >             </solid>             <!-- view border color , width (i want change this) -->             <stroke                 android:width="1dp"                 android:color="@color/white" >             </stroke>             <!-- if want add padding -->             <padding                 android:left="4dp"                 android:top="4dp"                 android:right="4dp"                 android:bottom="4dp"    >             </padding>         </shape>     </item> </layer-list> 

then have layout how each card/list item looks (list_row.xml):

<?xml version="1.0" encoding="utf-8"?> <linearlayout android:background="@drawable/feed_item"     android:id="@+id/card"     android:layout_height="match_parent"     android:layout_width="match_parent"     android:orientation="vertical"     android:padding="2dp"     xmlns:android="http://schemas.android.com/apk/res/android">      <textview android:id="@+id/title"         android:layout_height="wrap_content"         android:layout_margin="4dp"         android:layout_width="wrap_content"         android:text="mmmmmmmmmm"         android:textsize="@dimen/name3"         android:textcolor="@color/black"   />      <!--android:scaletype="fitxy"-->     <imageview android:id="@+id/list_image"         android:layout_height="180dp"         android:layout_margin="2dp"         android:layout_weight="0.04"         android:layout_width="match_parent"         android:scaletype="centerinside"         android:adjustviewbounds="true"         android:src="@mipmap/navigation_refresh"/>      <textview android:id="@+id/description"         android:layout_height="wrap_content"         android:layout_margin="4dp"         android:layout_width="wrap_content"         android:text="mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm"         android:textsize="@dimen/description3"         android:textcolor="@color/black" />  </linearlayout> 

now, have fragment listview. fragment tutorial (show 8 cards). i've added button fragment want change specific cards border color (in fragments onactivitycreated):

newpost = (button) getactivity().findviewbyid(r.id.reply); newpost.setonclicklistener(new view.onclicklistener() {     @override     public void onclick(view v) {          layerdrawable layers = (layerdrawable) getactivity().getresources().getdrawable(r.drawable.feed_item);          gradientdrawable shape = (gradientdrawable) (layers.finddrawablebylayerid(r.id.feedsquare));         shape.setstroke(1 ,r.color.green);      } }); 

nothing happens when press button. ideas can do?

to show selected item (row) in listview :

  1. create variable in adapter class :

private int selectedposition = 0;

  1. create method in side adapter :

     public void setselecteditem(int position) { this.selectedposition = position; notifydatasetchanged(); }  
  2. add check in getview methode

    if (position == selectedposition) { convertview.setbackground(context.getresources().getdrawable(r.drawable.selector_rect_black_trans_bg)); } else convertview.setbackgroundcolor(context.getresources().getcolor(android.r.color.transparent));

  3. selector_rect_black_trans_bg.xml :

    <solid android:color="@color/gray1" />  <stroke     android:width="2dp"     android:color="@color/gray6" />  <corners     android:bottomleftradius="0dp"     android:bottomrightradius="0dp"     android:topleftradius="0dp"     android:toprightradius="0dp" /> 

in activity, need pass position in adapter show highlighted. tested code , work.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -