Acts 16:22-25 (NIV)
The crowd joined in the attack against Paul and Silas, and the magistrates ordered them to be stripped and beaten. After they had been severely flogged, they were thrown into prison, and the jailer was commanded to guard them carefully. Upon receiving such orders, he put them in the inner cell and fastened their feet in the stocks.
About midnight Paul and Silas were praying and singing hymns to God, and the other prisoners were listening to them.
How could these men sing hymns at a time like this? They were beaten, whipped, locked up, and put in stocks. The verse says that the other prisoners were listening to them. I can imagine the other prisoners beginning with disgust, then moving to amazement and finally desiring the same kind of joy that Paul and Silas had. Praise for God for the Christian does not come because of circumstances. It comes because of their trust in God and because he is worthy of praise at all times. One thing I've noticed about feelings and praise: If you wait until you feel like it, it will only rarely happen. But if you praise God in spite of your feelings, the feelings will then begin to follow.
Philippians 4:4 (NKJV)
Rejoice in the Lord always. Again I will say, rejoice!