在Android中Listitem onclick动作错误

时间:2011-10-27 13:09:26

标签: android

我在android中显示列表视图。当我点击特定页面应打开的每个项目时。因此,我编写了以下代码。

package com.splash;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class Information extends Activity {
    private String[] Countries;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.information);

        Countries = getResources().getStringArray(R.array.countries);

        ListView list = (ListView)findViewById(R.id.list);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.row, Countries);
        list.setAdapter(adapter);
        registerForContextMenu(list);

    }

    protected void onListItemClick(ListView l, View v, int position, long id) {
        // Get the item that was clicked
Object o = this.getListAdapter().getItem(position);
String keyword = o.toString();
if((keyword.equals("test1"))){




    Intent intent=new Intent(getApplicationContext(),lvereview.class);
       startActivity(intent);
}
else if(keyword.equals("test2")){




 Intent i = new Intent("android.intent.action.VIEW", Uri.parse("http://www.Facebook.com/canadaqbank"));
 startActivity(i);
}
else if(keyword.equals("test3")){




       Intent intent=new Intent(getApplicationContext(),recommendfriend.class);
       startActivity(intent);
    }
else if(keyword.equals("test3")){




       Intent i = new Intent("android.intent.action.VIEW", Uri.parse("http://www.Facebook.com/canadaqbank"));
       startActivity(i);
    }
else if(keyword.equals("test4")){




       Intent intent=new Intent(getApplicationContext(),ContactUs.class);
       startActivity(intent);
    }
else if(keyword.equals("test5")){




       Intent intent=new Intent(getApplicationContext(),receiveemail.class);
       startActivity(intent);
    }

else
{



    Intent intent=new Intent(getApplicationContext(),Otherapps.class);
      startActivity(intent);
}

//tabView.setCurrentView(R.layout.rowlayout);
//setContentView(tabView.render(2));
}



}

这里我在strings.xml文件中创建了列表项。当我执行此代码时,它显示“方法getListAdapter()未定义类型信息”。这里有什么问题...为什么我不能使用该方法?任何建议都会有所帮助......

1 个答案:

答案 0 :(得分:0)

扩展ListActivity,而不是Activity