嘿有人可以告诉我,我怎么能由$ P $开始活动pssing在ListView的项目?
下面是一种预感,我有:
修改 - 我有固定它,我想becuse我没有得到任何错误消息。但是当我开始这项活动(视频)应用程序carshes并希望强制关闭什么问题?帮助请:D
下面是源$ C $ C -
包com.alpha.liveshit;
进口android.app.ListActivity;
进口android.content.Intent;
进口android.os.Bundle;
进口android.view.View;
进口android.widget.ArrayAdapter;
进口android.widget.ListView;
公共类视频扩展ListActivity {
的String []元素= {视频,菜单};
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.videos);
ListView控件列表视图=(ListView控件)findViewById(R.id.listView1);
listview.setAdapter(新ArrayAdapter<字符串>(这一点,android.R.layout.simple_list_item_1,元素));
}
公共无效onListItemClick(ListView的父,视图V,INT位置,长的id){
如果(视频.equals(元素[位置]))
{意向myIntent =新的意图(Videos.this,Lars.class);
startActivity(myIntent);}
否则,如果(菜单.equals(元素[位置]))
{意向myIntent =新的意图(Videos.this,MenuActivity.class);
startActivity(myIntent);}
}
}
![Android 自定义ListView控件](/d/file/2023/09-17/f4a36167abdc7cda02a355a0fb940d43.png)
解决方案
请确保你所添加的活性到Android清单 在你的manifest文件,你应该加入该活动是这样的:
<活动机器人:名称=拉斯/>
请一定要为你做这个计划使用的每个意图和活动。
Hey can someone tell me how I can start an activity by pressing an item in a listview?
Here is a hunch I have:
EDIT- I have fixed it i think becuse i get no error messages. but when i will start this activity (Videos) the app carshes and wants to force close whats the problem? help pls :D
Here is the source code-
package com.alpha.liveshit;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Videos extends ListActivity {
String[] elements = {"video", "menu"};
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videos);
ListView listview = (ListView)findViewById(R.id.listView1);
listview.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, elements));
}
public void onListItemClick(ListView parent, View v, int position, long id) {
if ("video".equals(elements[position]))
{Intent myIntent = new Intent(Videos.this, Lars.class);
startActivity(myIntent);}
else if ("menu".equals(elements[position]))
{Intent myIntent = new Intent(Videos.this, MenuActivity.class);
startActivity(myIntent);}
}
}
解决方案
Make sure you are adding the activity to the Android manifest In your manifest file you should add the activity like this:
<activity android:name=".Lars"/>
make sure to do this for each Intent and activity you plan to use.
相关推荐
最新文章