通过设置一个活动链接的新页面 [英] Setting new pages linked by an Activity

查看:89
本文介绍了通过设置一个活动链接的新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我写的应用程序,我有一个扩展ListActivity主类 - 它包含元素的列表。我想这些内容链接到不同的网页(一个XML之一,或者一个视图对象)。但是,我意识到我们不能使用的方法的setContentView(INT) A ListActivity对象。

In the application I am writing, I have a main class which extends the ListActivity - it contains a list of elements. I want these elements to link to a different page (an xml one, or perhaps a View object). However, I realised one cannot use the method setContentView(int) on a ListActivity object.

什么是做什么?

谢谢!

推荐答案

看起来你都争相推出了新的活动。

Looks like you are trying to launch a new activity.

您必须覆盖 ListActivity onListItemClick 方法。

下面是code。

// ListView l points to list view whose item user clicked
// View v points to the item in the list view on which the user clicked
// int position is the position index of the item in the list
// long id is the id assigned to the item. This id is assigned using the ListAdapter, CursorAdapter etc.
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);

    // I am using getApplicationContext() as it is more safe then just passing `this`
    Intent i = new Intent(this.getApplicationContext(), ActivityToRun.class);

    this.startActivity(i);
}

请注意:你必须根据你的需求来改善这个骨架

NOTE: You have to improve on this skeleton depending upon your needs.

这篇关于通过设置一个活动链接的新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆