Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Listview not showing the last item

My Problem is the last item in the listview is not displaying even though it has been added to the adapter and as well as in the list as i can see the number of items in the adapter is ok. Is it the problem with the layout? this is my 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/golive_bg"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <EditText
        android:id="@+id/Room"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10" >

        <requestFocus android:layout_width="wrap_content" />

    </EditText>

    <Button
        android:id="@+id/Search1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Search" />

    <ImageButton
        android:id="@+id/CreateRoomimageButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/closed_doorplus" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
        <ListView
            android:id="@+id/listRooms"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fastScrollEnabled="true"
            android:transcriptMode="alwaysScroll">
        </ListView>
</LinearLayout>

</LinearLayout>

This is my class activity

public class chatRoomsListActivity extends Activity implements OnScrollListener  {

private static String Password;
private ListView lv;
private static Collection<HostedRoom> rooms;
private static ArrayList<String> Roomlist = new ArrayList<String>();
private static Handler mHandler = new Handler();
private Button SearchButton;
private ImageButton CreateButton;
private EditText EditTextSearch;
private String Search;
private String RoomName;
private static ChatRoomListAdapter adapter;
private static String Nickname="";

@Override 
public void onCreate(Bundle savedInstanceState)
        {

            super.onCreate(savedInstanceState);
            setContentView(R.layout.chat_rooms);

            SearchButton=(Button)findViewById(R.id.Search1);
            CreateButton=(ImageButton)findViewById(R.id.CreateRoomimageButton);
            lv = (ListView) findViewById(R.id.listRooms);        

            adapter = new ChatRoomListAdapter(getApplicationContext(),  
R.layout.chat_rooms_wrapper);
            lv.setAdapter(adapter);
            //ScrollView.measureChildWithMargins();

            try {
            populate_RoomList();
        } catch (XMPPException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }     
          addListenerOnButton();


/*   
             arrayAdapter = new ArrayAdapter<String>(
                     this,android.R.layout.simple_list_item_1,Roomlist);            
             lv.setAdapter(arrayAdapter);   
             */


             lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parnet,    
android.view.View view,
                            int position, long id) {

                    setRoomName(ChatRoomListAdapter.getItemName(position));
                    showOptionDialog();

                    }
                });      
            addListenerOnButton();

        }

public void addListenerOnButton() {      
            final Context context = this;
                CreateButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View arg0) {
                    createRoomDialog();                 
                }

            }); 

            SearchButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View arg0) {

                     EditTextSearch=(EditText) findViewById(R.id.Room);
                     Search=EditTextSearch.getText().toString();
                    //Search=Search.concat("*");

                         try {
                            // populate_RoomList();
                             getSearchlist();
                            // updateList();
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }

                }

            });
        }

public void getSearchlist() throws XMPPException{

        Roomlist.clear();
        adapter.clear();
        ChatRoomListAdapter.getChatRoom().clear();

        rooms=getHostedRooms(MyService.getConnection(),"conference."+  
MyService.getDomain());

              System.out.println("in getsearch");
            for (HostedRoom h : rooms)
            {
                System.out.println(h.getName().toString()+" contain " +Search);
                if(h.getName().toString().contains(Search)){
                System.out.println("roomlist= " +h.getJid().toString());

                Roomlist.add(h.getName());


System.out.println("ChatRooms.IsRoomPassProtected(h.getName())==   
"+ChatRooms.IsRoomPassProtected(h.getName()));

                if(ChatRooms.IsRoomPassProtected(h.getName())==true){
                    adapter.add(new ChatRoom(h.getName(),true));
                }
                else if(ChatRooms.IsRoomPassProtected(h.getName())==false){
                    adapter.add(new ChatRoom(h.getName(),false));
                 }

                  }
            }
            System.out.println("Adapter count="+adapter.getCount());
        }


private void populate_RoomList() throws XMPPException {

            //chatRoomsList.getRooms();"
            Roomlist.clear();
            adapter.clear();
            //rooms.clear();
            ChatRoomListAdapter.getChatRoom().clear();

            rooms=getHostedRooms(MyService.getConnection(),"conference."+  
MyService.getDomain());
            //System.out.println(rooms.iterator().next().getName());

            for (HostedRoom h : rooms)
            {
                System.out.println("roomlist= " +h.getName().toString());
                Roomlist.add(h.getName());

System.out.println("ChatRooms.IsRoomPassProtected(h.getName())==   
"+ChatRooms.IsRoomPassProtected(h.getName()));

                if(ChatRooms.IsRoomPassProtected(h.getName())==true){
                    adapter.add(new ChatRoom(h.getName(),true));
                }
                else if(ChatRooms.IsRoomPassProtected(h.getName())==false){
                    adapter.add(new ChatRoom(h.getName(),false));
                }

            }

            System.out.println("Adapter count="+adapter.getCount());

        }



public void setRoomName(String roomName) {
            RoomName = roomName;
        }

public static Collection<HostedRoom> getHostedRooms(Connection connection, String serviceName)
                throws XMPPException {
            List<HostedRoom> answer = new ArrayList<HostedRoom>();
            ServiceDiscoveryManager discoManager = new       
ServiceDiscoveryManager(connection);
            DiscoverItems items = discoManager.discoverItems(serviceName);
            for (Iterator<DiscoverItems.Item> it = items.getItems(); it.hasNext();) {
                answer.add(new HostedRoom(it.next()));
            }
            return answer;
        }   

}

And this is my custom adapter

public class ChatRoomListAdapter extends ArrayAdapter<ChatRoom> {

private TextView name;
private static List<ChatRoom>  ChatRoom = new ArrayList<ChatRoom>();
private LinearLayout wrapper;
private ImageView lock;
public ChatRoomListAdapter(Context context, int textViewResourceId) {
    super(context, textViewResourceId);
}


public static List<ChatRoom> getChatRoom() {
    return ChatRoom;
}


public static void setChatRoom(List<ChatRoom> chatRoom) {
    ChatRoom = chatRoom;
}


public ChatRoom getItem(int index) {
    return ChatRoomListAdapter.ChatRoom.get(index);
}

public static String getItemName(int index) {
    return ChatRoomListAdapter.ChatRoom.get(index).name;
}


public static void setfriends(List<Friends> friends) {
    FriendListAdapter.setFriends(friends);
}

public void add(ChatRoom object) {
System.out.println("IN Chat room list adapter "+" addded");
ChatRoomListAdapter.ChatRoom.add(object);
    super.add(object);

}

public void remove(ChatRoom object) {
    ChatRoom.remove(object);
    super.remove(object);
}

public View getView(int position, View convertView, ViewGroup parent) {
    View row = convertView;
    if (row == null) {
        LayoutInflater inflater = (LayoutInflater)     
this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        row = inflater.inflate(R.layout.chat_rooms_wrapper, parent, false);
    }

    wrapper = (LinearLayout) row.findViewById(R.id.C_R_wrapper);

    name = (TextView) row.findViewById(R.id.C_R_RoomName);
    lock=(ImageView)row.findViewById(R.id.C_R_Lock);

    try {
         Log.d("Chat room adapter", "heere");
         ChatRoom CR= getItem(position);
         System.out.println("name= "+CR.name);
         name.setText(CR.name);

            if(CR.lock==true)
            {
                lock.setImageResource(R.drawable.lock_lock_icon);
            }else{
                lock.setImageResource(R.drawable.lock_unlock_icon);
            }


    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }   



return row;

}


public Bitmap decodeToBitmap(byte[] decodedByte) {
    return BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length);
}



}

Thanks in advance.

like image 488
Fallak Asad Avatar asked Dec 31 '25 12:12

Fallak Asad


1 Answers

Add this line to your Viewpager

android:layout_marginBottom="?attr/actionBarSize"

because the size you don't have at the bottom is exactly the size taken by your Toolbar

Example with RecyclerView

<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view_trips"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="vertical"
    android:layout_marginBottom="?attr/actionBarSize"/>

Example with Viewpager

<android.support.v4.view.ViewPager
    android:id="@+id/viewpager_trip_history"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="?attr/actionBarSize" />
like image 173
Anand Saggam Avatar answered Jan 03 '26 02:01

Anand Saggam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!