2014-12-23 25 views
-1
package com.example.luke.sinhalasindu; 

import android.support.v7.app.ActionBarActivity; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.app.Activity; 
import android.content.Intent; 
import android.view.Menu; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 


public class HomePage extends Activity implements OnClickListener { 

    Button bntoartistpage; 
    Button bntonewmp3page; 


    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_home_page); 

     bntoartistpage = (Button) findViewById(R.id.bntoartistpage); 
     bntoartistpage.setOnClickListener(this); 

     bntonewmp3page = (Button) findViewById(R.id.bntonewmp3page); 
     bntonewmp3page.setOnClickListener(this); 
    } 


    @Override 
    public void onClick(View view) { 
     Intent inent = new Intent(this, Artist.class); 

     // calling an activity using <intent-filter> action name 
     // Intent inent = new Intent("com.example.luke.sinhalasindu"); 
     startActivity(inent); } 

     @Override 

     public void onClick(View view){ 
     Intent inent = new Intent(this, NewMp3.class); 
     // calling an activity using <intent-filter> action name 
     // Intent inent = new Intent("com.example.luke.sinhalasindu"); 
     startActivity(inent); } 

} 
+0

請提供更多關於你想要實現的內容 –

回答

1
Button bntoartistpage = (Button) findViewById(R.id.bntoartistpage); 
bntoartistpage.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     Intent inent = new Intent(this, Artist.class); 
     // calling an activity using <intent-filter> action name 
     // Intent inent = new Intent("com.example.luke.sinhalasindu"); 
     startActivity(inent); 
    } 
}); 

Button bntonewmp3page = (Button) findViewById(R.id.bntonewmp3page); 
bntonewmp3page.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     Intent inent = new Intent(this, NewMp3.class); 
     // calling an activity using <intent-filter> action name 
     // Intent inent = new Intent("com.example.luke.sinhalasindu"); 
     startActivity(inent); 
    } 
}); 
1

你不能在一個活動使用兩種onClick()方法。使用這個

@Override 
public void onClick(View view) { 
    if(view.getId() == R.id.bntoartistpage) 
    { 
     Intent inent = new Intent(this, Artist.class); 
     // calling an activity using <intent-filter> action name 
     // Intent inent = new Intent("com.example.luke.sinhalasindu"); 
     startActivity(inent); 
    } 
    else if(view.getId() == R.id.bntonewmp3page) 
    { 
     Intent inent = new Intent(this, NewMp3.class); 
     // calling an activity using <intent-filter> action name 
     // Intent inent = new Intent("com.example.luke.sinhalasindu"); 
     startActivity(inent); 
    } 
}