gpt4 book ai didi

android - 单击 ListAdapter 中的项目不会执行任何操作

转载 作者:行者123 更新时间:2023-11-29 16:11:03 26 4
gpt4 key购买 nike

我正在尝试使用 android 制作我的第一个列表适配器,它随列表一起出现,但是当我单击项目时,没有任何反应。我唯一的猜测是我在定义 Class cvar 的行之后的注释。

package scouting.form;

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 Menu extends ListActivity{

String classes[] = {"SCOUTING","LOGIN","MAIN"};

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Menu.this,android.R.layout.simple_list_item_1,classes));
}

@Override
protected void onListItemClick(ListView l, View v, int position,long id)
{
super.onListItemClick(l, v, position, id);
String cheese= "com.cody.graham."+classes[position];
try{
Class cvar=Class.forName(cheese); //Eclipse has a warning on this line "Class is a raw type. References to generic type Class<T> should be parameterized". I don't really know what that means.
Intent intention=new Intent(Menu.this,cvar);
startActivity(intention);
}catch(ClassNotFoundException e){
e.printStackTrace();
}
}
}

编辑:

AndroidManifest 的一部分:

<activity android:name=".splash_screen" android:label="@string/title_activity_splash" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".Login" android:label="@string/title_activity_login" android:exported="false">
<intent-filter>
<action android:name="com.cody.graham.LOGIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

<activity android:name=".Scouting" android:label="@string/title_activity_scouting" android:exported="false">
<intent-filter>
<action android:name="com.cody.graham.SCOUTING" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

最佳答案

  String classes[] = {"SCOUTING","LOGIN","MAIN"};

尝试以其出现的方式命名类。喜欢Scouting

同时尝试更改您的 list :

<activity android:name=".Scouting" />
这是您在这种情况下只需要的。

Eclipse has a warning on this line "Class is a raw type. References to generic type Class should be parameterized". This is a warning, it will not give you an error in this case. What is means is Class , T is a class type of what you are getting. ex:

Class<? extends Activity> cvar=Class.forName(cheese);

更多信息:link

关于android - 单击 ListAdapter 中的项目不会执行任何操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13299568/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com