安卓:意向要求删除参数和放大器; getBaseContext()要求创建其方法 [英] Android: Intent asks remove argument & getBaseContext() ask to create its method

查看:143
本文介绍了安卓:意向要求删除参数和放大器; getBaseContext()要求创建其方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让3个标签从<一个片段href=\"http://stackoverflow.com/questions/17227855/tabhost-with-fragments-and-fragmentactivity\">TabHost与片段和FragmentActivity ,并发现问题,我在第三个标签的意图。这个方法我试过的Andr​​oid删除的参数匹配&QUOT;意向()&QUOT; 但没有什么变化。它仍然是错误。

 包com.spamcity;进口android.content.Context;
进口android.content.Intent;
进口android.os.Bundle;
进口android.support.v4.app.Fragment;
进口android.widget.ImageButton;
进口android.view.LayoutInflater;
进口android.view.View;
进口android.view.ViewGroup;
进口android.view.View.OnClickListener;公共类postingActivity扩展片段{    私人的ImageButton基础设施;
    私人的ImageButton trafficjam;
    私人的ImageButton他人;    @覆盖
    公共查看onCreateView(LayoutInflater充气器,容器的ViewGroup,
            捆绑savedInstanceState){
            //充气的布局该片段
            查看V = inflater.inflate(R.layout.posting_activity,集装箱,FALSE);        setupVariables();
        addListenerOnButton();
        返回伏;
    }    公共无效addListenerOnButton(){
        意向意图=新意图(getBaseContext(),writeActivity.class); //错误
        //要我创建方法getBaseContext()    //基础设施
        infrastructure.setOnClickListener(新OnClickListener(){
            @覆盖
            公共无效的onClick(查看为arg0){
                startActivity(意向); //错误
                完();
            }
        });    // 交通阻塞
        trafficjam.setOnClickListener(新OnClickListener(){
            @覆盖
            公共无效的onClick(查看为arg0){
                startActivity(新意图(postingActivity.this,writeActivity.class)); //错误
                完();
            }
        });    // 其他
        others.setOnClickListener(新OnClickListener(){
            @覆盖
            公共无效onCzlick(查看为arg0){
                startActivity(新意图(postingActivity.this,writeActivity.class)); //错误
                完();
            }        });    }    保护无效完成(){
        // TODO自动生成方法存根
        //它们需要此方法中存在
        //但我不知道我应该怎么写在这里
    }    私人无效setupVariables(){
        基础设施=(的ImageButton)findViewById(R.id.btnInfra);
        trafficjam =(的ImageButton)findViewById(R.id.btnTrafJam);
        其他=(的ImageButton)findViewById(R.id.btnOther);
    }
}

我不明白出了什么错在这里。感谢试图帮助。


解决方案

 进口android.content.Context;
进口android.content.Intent;
进口android.os.Bundle;
进口android.support.v4.app.Fragment;
进口android.widget.ImageButton;
进口android.view.LayoutInflater;
进口android.view.View;
进口android.view.ViewGroup;
进口android.view.View.OnClickListener;公共类postingActivity扩展片段{    私人的ImageButton基础设施;
    私人的ImageButton trafficjam;
    私人的ImageButton他人;    @覆盖
    公共查看onCreateView(LayoutInflater充气器,容器的ViewGroup,
            捆绑savedInstanceState){
            //充气的布局该片段
            查看V = inflater.inflate(R.layout.posting_activity,集装箱,FALSE);
            基础设施=(的ImageButton)V.findViewById(R.id.btnInfra);
            trafficjam =(的ImageButton)V.findViewById(R.id.btnTrafJam);            其他=(的ImageButton)V.findViewById(R.id.btnOther);
        addListenerOnButton();
        返回伏;
    }    公共无效addListenerOnButton(){
        最终意向意图=新意图(getActivity(),writeActivity.class); //错误
        //要我创建方法getBaseContext()    //基础设施
        infrastructure.setOnClickListener(新OnClickListener(){
            @覆盖
            公共无效的onClick(查看为arg0){
                startActivity(意向); //错误
                getActivity()完成()。
            }
        });    // 交通阻塞
        trafficjam.setOnClickListener(新OnClickListener(){
            @覆盖
            公共无效的onClick(查看为arg0){
                startActivity(新意图(getActivity(),writeActivity.class)); //错误
                getActivity()完成()。
            }
        });    // 其他
        others.setOnClickListener(新OnClickListener(){
            @覆盖
            公共无效的onClick(查看为arg0){
                startActivity(新意图(getActivity(),writeActivity.class)); //错误
               getActivity()完成()。
            }        });    }
}

这正常工作
试试这个

I'm trying to make 3 tabs with fragments from TabHost with Fragments and FragmentActivity and find problems with my intent in 3rd tab. I tried this method Android Remove arguments to match "intent()" but nothing change. it's still error.

    package com.spamcity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.widget.ImageButton;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;

public class postingActivity extends Fragment {

    private ImageButton infrastructure;
    private ImageButton trafficjam;
    private ImageButton others;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
            // Inflate the layout for this fragment
            View V = inflater.inflate(R.layout.posting_activity, container, false);

        setupVariables();
        addListenerOnButton();
        return V; 
    }

    public void addListenerOnButton() {
        Intent intent = new Intent(getBaseContext(), writeActivity.class); // error
        // want me to create method getBaseContext()

    // infrastructure
        infrastructure.setOnClickListener(new OnClickListener() { 
            @Override
            public void onClick(View arg0) {
                startActivity(intent); //error
                finish(); 
            } 
        });

    // traffic jam
        trafficjam.setOnClickListener(new OnClickListener() {            
            @Override
            public void onClick(View arg0) {
                startActivity(new Intent(postingActivity.this, writeActivity.class)); // error
                finish();
            } 
        });

    // others
        others.setOnClickListener(new OnClickListener() {            
            @Override
            public void onCzlick(View arg0) {
                startActivity(new Intent(postingActivity.this, writeActivity.class)); // error
                finish();
            }

        });

    }

    protected void finish() {
        // TODO Auto-generated method stub
        // they require this method to be exist
        // but I dont know what should I write here
    }

    private void setupVariables(){
        infrastructure = (ImageButton) findViewById(R.id.btnInfra);
        trafficjam = (ImageButton) findViewById(R.id.btnTrafJam);
        others = (ImageButton) findViewById(R.id.btnOther);
    }
}

I don't understand what went wrong here. thanks for trying to help.

解决方案

   import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.widget.ImageButton;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;

public class postingActivity extends Fragment {

    private ImageButton infrastructure;
    private ImageButton trafficjam;
    private ImageButton others;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
            // Inflate the layout for this fragment
            View V = inflater.inflate(R.layout.posting_activity, container, false);
            infrastructure = (ImageButton) V.findViewById(R.id.btnInfra);
            trafficjam = (ImageButton) V.findViewById(R.id.btnTrafJam);

            others = (ImageButton) V.findViewById(R.id.btnOther);
        addListenerOnButton();
        return V; 
    }

    public void addListenerOnButton() {
        final Intent intent = new Intent(getActivity(), writeActivity.class); // error
        // want me to create method getBaseContext()

    // infrastructure
        infrastructure.setOnClickListener(new OnClickListener() { 
            @Override
            public void onClick(View arg0) {
                startActivity(intent); //error
                getActivity().finish(); 
            } 
        });

    // traffic jam
        trafficjam.setOnClickListener(new OnClickListener() {            
            @Override
            public void onClick(View arg0) {
                startActivity(new Intent(getActivity(), writeActivity.class)); // error
                getActivity().finish();
            } 
        });

    // others
        others.setOnClickListener(new OnClickListener() {            
            @Override
            public void onClick(View arg0) {
                startActivity(new Intent(getActivity(), writeActivity.class)); // error
               getActivity().finish();
            }

        });

    }




}

this works properly try this

这篇关于安卓:意向要求删除参数和放大器; getBaseContext()要求创建其方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆