2013-03-06 16 views
0

我有一個問題我創建了一個簡單的列表項目,我的項目是娛樂我已經創建了XML和Java文件,但運行到模擬器後它不起作用。我的意思是列表項目的工作,娛樂在這裏,但點擊它不會讓它到下一個。幫助新手在android編程,xml和類文件不工作

這是主要的活動文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".Main" > 

    <ListView 
     android:id="@+id/listView1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" > 
    </ListView> 

</RelativeLayout> 

這是Java文件:

package com.firstapp; 

import android.app.Activity; 
import android.content.Intent; 

import android.media.MediaPlayer; 
import android.net.Uri; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.VideoView; 

public class Entertainment extends Activity { 

    MediaPlayer ourSong; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.entertainment); 
     ourSong = MediaPlayer.create(this, R.id.videoView1); 
     ourSong.start(); 
     Thread timer = new Thread() { 
      public void run() { 
       try { 
        sleep(5000); 

       } catch (InterruptedException e) { 
        e.printStackTrace(); 

       } finally { 
        Intent openStartingpoint = new Intent(
          "com.bucky.android.Menu"); 
        startActivity(openStartingpoint); 

       } 
      } 
     }; 

     timer.start(); 
    } 

    @Override 
    protected void onPause() { 
     // TODO Auto-generated method stub 
     super.onPause(); 
     ourSong.release(); 
     finish(); 

    } 

} 

這是清單

<uses-sdk 
    android:minSdkVersion="9" 
    android:targetSdkVersion="16" /> 

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name="com.firstapp.Main" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </activity> 

    <activity 
     android:name="com.firstapp.Entertainment" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.Main" /> 

      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </activity> 
</application> 

+0

你在AndroidMenifest中定義了你的'Menu'活動? – GrIsHu 2013-03-06 12:24:40

+0

哪個是您的啓動器活動? – GrIsHu 2013-03-06 12:25:15

回答

1

在清單中,在主要活動的意圖標籤「類別」是錯誤的:

<activity 
     android:name="com.firstapp.Main" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 

您必須聲明,而不是省的Launcher。看看這個改變後它是否有效。

0

你必須覆蓋itemClick在您的列表視圖的方法爲

@Override 
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { 
    int position = arg2; 

    // click event handling 
    textQuestionCount.setText("Question " + String.valueOf(position + 1) + " of " + arg0.getCount()); 

    } 

,並實現你的類接口OnItemClickListener

相關問題