package com.example.app;
import com.example.app.adaptor.*;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
public class ListviewExample extends ListActivity {
static final String[] ASDFGH = new String[] { "ABC", "PQR",
"XYZ", "RAA","AA" };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new etcArray(this, main_activity));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// get selected items
String selectedValue = (String) getListAdapter().getItem(position);
if(selectedValue.equalsIgnoreCase("ABC"))
{
Intent in = new Intent(getApplicationContext(),ABC.class);
startActivity(in);
}
else
if(selectedValue.equalsIgnoreCase("AA"))
{
Intent in = new Intent(getApplicationContext(),AA.class);
startActivity(in);
}
}
在上面的程序..使用正常情況下,如果string.equalsIgnorecase(「AA」) 我們可以啓動該具體點擊的意圖!是否有任何方法來啓動任何listview項目點擊???如何在Listview(item)上加載特定活動(Intent)單擊?
謝謝你的幫助..類型不匹配錯誤:你不能將String []轉換爲Class [] – Xy1ys
請檢查更新現在..實際上它是Class對象。錯誤我寫了String .. –