开发者

Back button function in android

开发者 https://www.devze.com 2023-03-08 09:24 出处:网络
Hi i have three column in database 1)topic 2)subtopic 3)imagename.first i am getting all topic from db in listview. in on clicklistitem am getting subtopic where topic equal which an item i selected i

Hi i have three column in database 1)topic 2)subtopic 3)imagename.first i am getting all topic from db in listview. in on clicklistitem am getting subtopic where topic equal which an item i selected if there is no subtopic am directly displaying image.if subtopic present am displaying all subto开发者_StackOverflow中文版pic in listview then in onclick listitem am displaying image.now from image if i press backbutton it should list corresponding subtopic listview if it comes from subtopic listview else direct to main listview.how to do this?i couldnt display subtopic listview remaining working fine.


Hi bamini create a queue which will contain the view. means for the first time when application launches it will contain topic view only. when you go from topic to subtopic or image name insert those in queue. and on back key get the latest view set the view.

I have tested it. It is working as per your expectation.

Queue queue = new LinkedList();                        
queue.add(topic);
queue.add(subtopic);
queue.add(imagename);

setContentView ((View) queue.poll());

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        Object object = queue.poll();
        if (object != null) {
            setContentView((View) object);
        } else {
            finish();
        }
    }

    return false;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消