0

好的,现在我想不出这个,那应该很简单。我已经阅读了很多 StackOverflow 问题,但仍然一无所获。我只想在用户点击列表后开始一个新的活动。太简单了!

public class Lista2Activity extends ListActivity {
    TextView selection;
    String[] items={"lorem", "ipsum", "dolor", "sit", "amet",
                    "consectetuer", "adipiscing", "elit", "morbi", "vel",
                    "ligula", "vitae", "arcu", "aliquet", "mollis",
                    "etiam", "vel", "erat", "placerat", "ante",
                    "porttitor", "sodales", "pellentesque", "augue", "purus"};

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);
        setListAdapter(new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, items));
        selection=(TextView)findViewById(R.id.selection);
    }

    public void onListItemClick(ListView parent, View v, int position,long id) {
        super.onListItemClick(parent, v, position, id);

        selection.setText(items[position]);
        Intent hash=new Intent(getApplicationContext(),another.class);
        startActivity(hash);

    }
}

它在这方面失败了Intent

4

2 回答 2

1

利用

Intent hash=new Intent(YourActivity.this,another.class);
    startActivity(hash);

代替

 Intent hash=new Intent(getApplicationContext(),another.class);
    startActivity(hash);
于 2012-09-12T13:20:10.517 回答
0

您没有解释它究竟是如何“失败”的。然而,人们在尝试启动新活动时最常忘记的事情之一是在他们的 AndroidManifest.xml 文件中定义活动。对于每个 Activity 类,添加一个<activity/>节点作为节点的子<application/>节点:

<application ...>
...
    <activity android:name="fully.qualified.name.of.another.Class"/>
...
</application>

...其中android:name包含您的活动类的完全限定名称。

于 2012-09-11T19:33:24.540 回答