Skip to main content

android list view keep only the selected item marked

here i found a very useful solution
http://www.michenux.net/android-listview-highlight-selected-item-387.html

<ListView
       android:id="@android:id/list"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:choiceMode="singleChoice">
</ListView>
Then, you need to create a selector. This is where you will configure colors for each defined state. The selected file
is in res/drawable directory.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
   android:exitFadeDuration="@android:integer/config_mediumAnimTime">

   <item android:drawable="@android:color/holo_orange_dark" android:state_pressed="true"/>
   <item android:drawable="@android:color/holo_green_light" android:state_selected="true"/>
   <item android:drawable="@android:color/holo_green_light" android:state_activated="true"/>

</selector>
Then, on the item layout, add the attribute activatedBackgroundIndicator at top level:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:orientation="horizontal"
   android:background="?android:attr/activatedBackgroundIndicator">
    
    <!-- your item content-->
</LinearLayout>
Finally, you need to link the selector with your ListView. This can be done in method onCreate of a ListActivity or
in method onActivityCreated of a ListFragment.
this.getListView().setSelector(R.drawable.your_selector);
That’s all.
Update (2013/05/30) :
I didnot explain how to change the blue color.
Here is the solution :
Create a file res/drawable/listitem_background.xml with the following content :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_activated="true" android:drawable="@color/purple_dark" />
    <item android:drawable="@android:color/transparent" />
</selector>
Replace the @color/purple_dark with the color of your choice.
Then, in your theme, add the following line :
<item name="android:activatedBackgroundIndicator">@drawable/listitem_background</item>

Comments

Popular posts from this blog

itext 2.7.1 writing Arabic and English content in a PDF file

   public void createPdf(String filename) throws IOException, DocumentException {               Document document = new Document();           PdfWriter.getInstance(document, new FileOutputStream(filename));             document.open();             document.add(Chunk.NEWLINE);        FontFactory.register("c:/windows/fonts/tradbdo.ttf", "my_arabic");               Font myArabicFont = FontFactory.getFont("my_arabic" ,BaseFont.IDENTITY_H, BaseFont.EMBEDDED);         PdfPTable table = new PdfPTable(1);         table.getDefaultCell().setNoWrap(false);        // table.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);         PdfPCell text = new PdfPCell(new Phrase("محمود السنباطيthis is أبتثجحخدرزسشصضطظعغفقكلمنهوى", myArabicFont));         text.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);          text.setNoWrap(false);          table.addCell(text);     //Add the table to the document         document.add(table);                  

Installing liferay 6.2 on wildfly 10 app server and oracle 11g database & windows machine

*************************************DATABASE CREATION*********************************************************************************************** DOWNLOAD LIFERAY PORTAL SCRIPTS FROM https://www.liferay.com/downloads/liferay-portal/available-releases Rename the file as liferay.sql put it let say in under c drive , so it will be located like this  c:\liferay.sql from cmd dir c:\ SQLPLUS / AS SYSDBA @liferay.sql lportal lportal it will create the db ..after finishing go to sqlplus again to ggrant the below  to lportal user SQLPLUS / AS SYSDBA grant create session to lportal; grant connect to lportal; grant resource to lportal; *******************************CONFIGURE WILDFLY TO CONNECT TO ORACLE DB *****************************************************************************************************  configure wildfly to connect to oracle db Download the driver: ojdbc[VERSION].jar Create subfolders [WILDFLY_HOME]/modules/system/layers/base/com/oracle/main/ C

Fast Download with progress indication facility using Java NIO

package test; import java.io.FileOutputStream; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; import java.nio.ByteBuffer; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; import java.util.Date; public class DownloadProgressExample {     public static void main( String[] args ) {         new Downloader( "c:/header12.jpg", "http://www.daralshifa.com/images/mainheader/header12.jpg" );     }     private interface RBCWrapperDelegate {          // The RBCWrapperDelegate receives rbcProgressCallback() messages         // from the read loop.  It is passed the progress as a percentage         // if known, or -1.0 to indicate indeterminate progress.         //         // This callback hangs the read loop so a smart implementation will         // spend the least amount of time possible here before returning.         //         // One possible implementation is to push the progress message         // atomic