Android 方法必须重写超类方法

Android 方法必须重写超类方法,android,eclipse,Android,Eclipse,我现在正在学习一些android教程,为美国大学为期两周的夏令营做准备。我十七岁了,如果这是个愚蠢的问题,请原谅。我做了一些研究,尝试了几件事,但都没有成功 我使用的是谷歌标签/片段示例: 我的问题是当重写createTabContent和onTabChanged时,我不断得到错误,必须重写超类方法。这是我的密码: 包matthews.zack.test import java.util.ArrayList; import java.util.HashMap; import java.util.

我现在正在学习一些android教程,为美国大学为期两周的夏令营做准备。我十七岁了,如果这是个愚蠢的问题,请原谅。我做了一些研究,尝试了几件事,但都没有成功

我使用的是谷歌标签/片段示例:

我的问题是当重写createTabContent和onTabChanged时,我不断得到错误,必须重写超类方法。这是我的密码:

包matthews.zack.test

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TabHost;
import android.widget.TextView;
公共类测试活动扩展了碎片活动{

ListView list;
Button save;
RadioGroup radioGroup;
RadioButton selectedType;
TabHost tabHost;
// People p = new People();
public List<People> people = new ArrayList<People>();

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

    onInitialize();

    if (savedInstanceState != null) {
        tabHost.setCurrentTabByTag(savedInstanceState.getString("tab"));
    }
}

private void onInitialize() {

    tabHost = (TabHost) findViewById(R.id.tabHost);
    tabHost.setup();

     * TabManager tManager = new TabManager(this, tabHost,
     * R.id.realtabcontent); tManager.addTab(
     * tabHost.newTabSpec("details").setIndicator("Details",
     * getResources().getDrawable(R.drawable.goldstar)), null, null);
     * tManager.addTab( tabHost.newTabSpec("list").setIndicator("List",
     * getResources().getDrawable(R.drawable.bluestar)), null, null);
     *

     * TabSpec spec = tabHost.newTabSpec("tab1");
     * spec.setContent(R.id.listView1); spec.setIndicator("List",
     * getResources().getDrawable(R.drawable.goldstar));
     * 
     * TabSpec spec2 = tabHost.newTabSpec("tab2");
     * spec2.setContent(R.id.details); spec2.setIndicator("Details",
     * getResources().getDrawable(R.drawable.bluestar));
     * 
     * tabHost.addTab(spec); tabHost.addTab(spec2);
     */

    PeopleAdapter adapter = new PeopleAdapter();
    list = (ListView) findViewById(R.id.listView1);
    list.setAdapter(adapter);

    radioGroup = (RadioGroup) findViewById(R.id.type);
    // radioGroup.check(R.id.coWorker);
    radioGroup
            .setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

                public void onCheckedChanged(RadioGroup group, int checkedId) {
                    // TODO Auto-generated method stub

                    if (selectedType != (RadioButton) findViewById(radioGroup
                            .getCheckedRadioButtonId())) {
                        selectedType = (RadioButton) findViewById(radioGroup
                                .getCheckedRadioButtonId());
                    }
                }
            });

    save = (Button) findViewById(R.id.button1);
    save.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            People p = new People();

            // TODO Auto-generated method stub
            EditText firstName = (EditText) findViewById(R.id.editText1);
            EditText lastName = (EditText) findViewById(R.id.editText2);
            p.setFirstName(firstName.getText().toString());// firstName.getText().toString());
            p.setLastName(lastName.getText().toString());// lastName.getText().toString());
            p.setType(selectedType.getText().toString());

            people.add(p);
        }
    });
}

static class PeopleHolder {
    private TextView name;
    private TextView title;
    private ImageView icon;

    PeopleHolder(View row) {
        name = (TextView) row.findViewById(R.id.name);
        title = (TextView) row.findViewById(R.id.title);
        icon = (ImageView) row.findViewById(R.id.icon);
    }

    void populateForm(People p) {
        name.setText(p.getFirstName() + " " + p.getLastName());
        title.setText(p.getType().toString());
        if (p.getType().equals("Family")) {
            icon.setImageResource(R.drawable.android);

        }

        else if (p.getType().equals("Friend")) {
            icon.setImageResource(R.drawable.xbox);
        }

        else {
            icon.setImageResource(R.drawable.yinyang);
        }
    }

}

class PeopleAdapter extends ArrayAdapter<People> {

    PeopleAdapter() {
        super(_testActivity.this, android.R.layout.simple_list_item_1,
                people);
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        PeopleHolder holder = null;
        if (row == null) {
            LayoutInflater inflater = getLayoutInflater();
            row = inflater.inflate(R.layout.row, null);
            holder = new PeopleHolder(row);
            row.setTag(holder);
        }

        else {
            holder = (PeopleHolder) row.getTag();
        }

        holder.populateForm(people.get(position));

        return (row);
    }

}

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putString("tab", tabHost.getCurrentTabTag());
}

public static class TabManager implements TabHost.OnTabChangeListener {
    private final FragmentActivity activity;
    private final TabHost host;
    private final int containerID;
    private final HashMap<String, TabInfo> tabs = new HashMap<String, TabInfo>();
    TabInfo lastTab;

    static final class TabInfo {
        private final String tag;
        private final Class<?> clss;
        private final Bundle args;
        private Fragment fragment;

        TabInfo(String _tag, Class<?> clss, Bundle args) {
            this.tag = _tag;
            this.clss = clss;
            this.args = args;
        }
    }

    static class DummyTabFactory implements TabHost.TabContentFactory {
        private final Context context;

        public DummyTabFactory(Context context) {
            this.context = context;
        }

        public View createTabContent(String tag) {
            View v = new View(context);
            v.setMinimumWidth(0);
            v.setMinimumHeight(0);

            return v;
        }
    }

    public TabManager(FragmentActivity activity, TabHost host,
            int containerID) {
        this.activity = activity;
        this.host = host;
        this.containerID = containerID;
        this.host.setOnTabChangedListener(this);
    }

    public void addTab(TabHost.TabSpec tabSpec, Class<?> clss, Bundle args) {
        tabSpec.setContent(new DummyTabFactory(activity));
        String tag = tabSpec.getTag();

        TabInfo info = new TabInfo(tag, clss, args);

        info.fragment = activity.getSupportFragmentManager()
                .findFragmentByTag(tag);

        if (info.fragment != null && !info.fragment.isDetached()) {
            FragmentTransaction ft = activity.getSupportFragmentManager()
                    .beginTransaction();
            ft.detach(info.fragment);
            ft.commit();
        }

        tabs.put(tag, info);
        host.addTab(tabSpec);
    }

    public void onTabChanged(String tabId) {
        TabInfo newTab = tabs.get(tabId);
        if (lastTab != newTab) {
            FragmentTransaction ft = activity.getSupportFragmentManager()
                    .beginTransaction();
            if (lastTab != null) {
                if (lastTab.fragment != null) {
                    ft.detach(lastTab.fragment);
                }

            }

            if (newTab != null) {
                if (newTab.fragment == null) {
                    newTab.fragment =       Fragment.instantiate(activity,
                            newTab.clss.getName(), newTab.args);
                    ft.add(containerID, newTab.fragment, newTab.tag);

                }

                else {

                    ft.attach(newTab.fragment);
                }

            }

            lastTab = newTab;
            ft.commit();
            activity.getSupportFragmentManager()
                    .executePendingTransactions();

        }

        // TODO Auto-generated method stub

    }
}

}
ListView列表;
按钮保存;
放射组放射组;
单选按钮选择类型;
TabHost-TabHost;
//人物p=新人();
public List people=new ArrayList();
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
初始化();
如果(savedInstanceState!=null){
tabHost.setCurrentTabByTag(savedInstanceState.getString(“tab”);
}
}
私有void onInitialize(){
tabHost=(tabHost)findViewById(R.id.tabHost);
tabHost.setup();
*TabManager tManager=新的TabManager(此,tabHost,
*R.id.realtabcontent);tManager.addTab(
*tabHost.newTabSpec(“详细信息”).setIndicator(“详细信息”,
*getResources().getDrawable(R.drawable.goldstar)),null,null);
*tManager.addTab(tabHost.newTabSpec(“列表”).setIndicator(“列表”),
*getResources().getDrawable(R.drawable.bluestar)),null,null);
*
*TabSpec spec=tabHost.newTabSpec(“tab1”);
*spec.setContent(R.id.listView1);spec.setIndicator(“列表”,
*getResources().getDrawable(R.drawable.goldstar));
* 
*TabSpec spec2=tabHost.newTabSpec(“tab2”);
*spec2.setContent(R.id.details);spec2.setIndicator(“details”,
*getResources().getDrawable(R.drawable.bluestar));
* 
*tabHost.addTab(spec);tabHost.addTab(spec2);
*/
PeoDuceCapter适配器=新的PeoDuceCapter();
列表=(ListView)findViewById(R.id.listView1);
list.setAdapter(适配器);
放射组=(放射组)findViewById(R.id.type);
//放射组检查(R.id.同事);
放射组
.setOnCheckedChangeListener(新的RadioGroup.OnCheckedChangeListener(){
检查更改后的公共无效(RadioGroup组,int checkedId){
//TODO自动生成的方法存根
如果(selectedType!=(单选按钮)查找视图字节(radioGroup
.getCheckedRadioButtonId()){
selectedType=(单选按钮)findViewById(放射组
.getCheckedRadioButtonId());
}
}
});
保存=(按钮)findViewById(R.id.button1);
save.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
人物p=新人();
//TODO自动生成的方法存根
EditText firstName=(EditText)findViewById(R.id.editText1);
EditText lastName=(EditText)findViewById(R.id.editText2);
p、 setFirstName(firstName.getText().toString());//firstName.getText().toString());
p、 setLastName(lastName.getText().toString());//lastName.getText().toString());
p、 setType(selectedType.getText().toString());
新增(p);
}
});
}
静态类用户{
私有文本视图名称;
私有文本视图标题;
私有图像视图图标;
联系人(查看行){
name=(TextView)row.findViewById(R.id.name);
title=(TextView)row.findViewById(R.id.title);
icon=(ImageView)row.findViewById(R.id.icon);
}
无效的populateForm(人员p){
name.setText(p.getFirstName()+“”+p.getLastName());
title.setText(p.getType().toString());
if(p.getType().equals(“Family”)){
icon.setImageResource(R.drawable.android);
}
else if(p.getType().equals(“Friend”)){
icon.setImageResource(R.drawable.xbox);
}
否则{
icon.setImageResource(R.drawable.yinyang);
}
}
}
类适配器扩展了ArrayAdapter{
皮亚普特(){
超级(_testActivity.this,android.R.layout.simple_list_item_1,
人民);
}
公共视图getView(int位置、视图转换视图、视图组父视图){
视图行=转换视图;
PeopleHolder=null;
if(行==null){
LayoutInflater充气机=getLayoutInflater();
row=充气机。充气(R.layout.row,空);
持有者=新的人员持有者(世界其他地区);
row.setTag(支架);
}
否则{
holder=(PeopleHolder)行。getTag();
}
holder.populateForm(people.get(position));
返回(行);
}
}
@凌驾
SaveInstanceState上受保护的无效(束超出状态){
super.onSaveInstanceState(超出状态);
putString(“tab”,tabHost.getCurrentTabTag());
}
公共静态类TabManager实现TabHost.OnTabChangeListener{
私人最终碎片活动;
私有最终TabHost主机;
私人最终集装箱运输;
private final HashMap tabs=new HashMap();
TabInfo lastTab;
静态最终类TabInfo{
私有最终字符串标签;
私人期末班;
私有最终包args;
私有片段;
TabInfo(字符串_标记、类clss、捆绑参数){
this.tag=_tag;
this.clss=clss;
this.args=args;
}
}
静态类DummyTabFactory实现TabHost.TabContentFactory{
私人最终语境;
公共DummyTabFactory(上下文){
this.context=上下文;
}
公共视图createTabContent(字符串标记){
视图v=新视图(上下文);
v、 塞明
public class MyClass extends MySuperClass{...