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

标签 android eclipse listadapter

我正在尝试使用 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/

相关文章:

Android:具有枚举比较的数据绑定(bind)表达式

来自 Gradle 项目的 Java 项目

java - startActivityForResult 带有枚举

android - 在getView中获取ImageView宽度

android - adapter 的内容发生了变化但是 ListView 没有收到通知,后台没有更新

java - 如何在android中创建自定义开关控件

android - 识别 Android 平板电脑是否有 sim 卡插槽

java - 简单的服务器/客户端套接字连接?

java - 为什么我的 Android ListAdapter 只显示一项?

android - 单击另一个 Activity 中的单选按钮时,如何使按钮在一个 Activity 中可见?