一千萬個為什麽

搜索

如何把意圖放在Android的setOnItemClickListener?

希望你能幫我...

我有一個類,在那個類中有一個來自數據庫的列表視圖。

我的問題是我怎麽可以把setOnItemClickListener,所以如果我點擊在ListView中的項目去去

Intent(android.content.Intent.ACTION_VIEW,Uri.parse("http://maps.google.com/maps?f=d&saddr=&daddr="));

並且daddr從數據庫中獲得格值和長期價值。

這是我的編碼...

public class HotelList extends Activity{
hotelHelper dbHotelHelper;
protected Cursor cursor;
protected ListAdapter adapter;
ListView numberList;


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.hotellist);

    numberList = (ListView)findViewById(R.id.hotelListView);
    dbHotelHelper = new hotelHelper(this);
    try{
        dbHotelHelper.createDataBase();         
    }
    catch (Exception ioe){
        Log.e("err","Unable to create database");
    }        
    view();                 
}


private void view() {
   //TODO Auto-generated method stub
    SQLiteDatabase db = dbHotelHelper.getReadableDatabase();
    try{
        cursor = db.rawQuery("SELECT * FROM hoteltbl", null);
        adapter = new SimpleCursorAdapter(
                this, 
                R.layout.hotelview, 
                cursor, 
                new String[]{"name"}, 
                new int[] {R.id.hotelname}
                );
        numberList.setAdapter(adapter);     
    }
    catch (Exception e){
        Log.e("error",e.toString());
    }

}

}

我真的很感謝誰給我答案...

最佳答案

試試這種方式

numberList.setOnItemClickListener(new OnItemClickListener(){
      @Override
      public void onItemClick(AdapterView<?> arg0, View view, int position,long id) {
            startActivity(new Intent(android.content.Intent.ACTION_VIEW,Uri.parse("http://maps.google.com/maps?f=d&saddr=&daddr=1.481198,124.83572")));
      }
});

轉載註明原文: 如何把意圖放在Android的setOnItemClickListener?