custom adapter and highlighting a row [SOLVED]

Put your problem here if it does not fit any of the other categories.

custom adapter and highlighting a row [SOLVED]

Postby timcs » Mon Jul 29, 2013 9:24 pm


I have been having difficulty in getting a single row to be highlighted . The list is folders and files and I only want a single file to be highlighted.

My activity is a ListActivity and the layout(s) consist of a layout for the main display which includes a listview and then I have a separate row.xml to represent the folders or files . The main structure of this activity and its layouts is based on this tutorial :

the only difference is that I am trying to get a single file to be highlighted and the way I was directed in was a custom adapter. However I cannot get the highlighter to work correctly and quite often stays highlighted against a folder after moving back from a sub folder and before hand had selected a file within. the customer adapter code is as follows :

Code: Select all
public class FileListAdapter extends ArrayAdapter<String>  {

       private List<String> itemsll;

         public FileListAdapter(Context context, int row,
               List<String> iteml) {
            // TODO Auto-generated constructor stub
            this.itemsll = iteml;

         public View getView(int position, View convertView, ViewGroup parent) {
            View viewnull = convertView;
            if (viewnull == null) {
               LayoutInflater vrow;
               vrow = LayoutInflater.from(getContext());
               viewnull = vrow.inflate(R.layout.row, null);
            String currow =    itemsll.get(position);
            TextView rowtext = (TextView)viewnull.findViewById(;
            if (currpos == position) {
                } else {
            return viewnull;   


         public void setSelectedPosition( int pos )
              currpos = pos;


and I am currently using onListItemClick which is used to check if the selected row is a folder or file :

Code: Select all
    protected void onListItemClick(ListView l, View v, int position, long id) {
     // TODO Auto-generated method stub
     File fileci = new File(pathi.get(position));

     if (fileci.isDirectory())


      new AlertDialog.Builder(Importfile.this)
        .setTitle("[" + fileci.getName() + "] Cannot be accessed! Please try another folder")
        .setPositiveButton("OK", null).show();
     }    else {
          int selpos = position;

Thanks in Advance



Sorted this by using getListView() method to create a listview object as this is a ListActivity and then using the listview object set up OnItemClick and used the customadapter to allow me to slelect the row I need. I now only have one problem and that is to deselect a row but I aim to solve that hopefully by myself :)
Posts: 2
Joined: Thu Jan 12, 2012 8:33 pm


Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 7 guests