我正在開發一個android應用程序,並且我使用了片段類..我知道如何在Activity類中實現onclick監聽器,但是我發現它很難爲片段類做同樣的事情。使用onclick方法從片段類調用活動
這裏是我的片段類代碼
package info.eoilimited.tabPager.thespot;
import com.eoilimited.thespot.R;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.ImageView;
public class Resturants extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_resturant, container, false);
ImageView comment = (ImageView) rootView.findViewById(R.id.comment);
comment.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//I know I need to add the code here, but I don't know
//the right syntax
startActivity(new Intent());
}
});
return rootView;
}
}`
@覆蓋 \t公共無效的onClick(視圖v) \t { \t \t \t \t startActivity(新意圖(getActivity(Resturants.this),SignUpActivity.class)); \t} \t}); – eugbana
這是我的代碼,我仍然得到一個錯誤 – eugbana