2011-10-27 53 views
0

我在android中顯示一個列表視圖。當我點擊特定頁面應該打開的每個項目時。因此,我寫了下面的代碼。Android的Listitem onclick動作錯誤

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()未定義類型信息」。這裏有什麼問題......爲什麼我不能使用該方法?任何建議將有所幫助....

回答