从导入的库继承多个类(Java - Android Studio)

时间:2017-03-04 17:53:05

标签: java android android-studio interface multiple-inheritance

我有一个类需要从其他两个类继承。 我需要我的portfoioActivity类来扩展Fragment类和AppCompatActivity类以使所有函数都能工作。我想过使用接口,但因为这些类是通过库导入的,所以我不知道从那里去哪里。我也尝试过聚合,但这也不起作用,但是再一次,我可能做错了,因为我是Java的新手。

public class portfolioActivity  {

    ListView portfolioList;
    String[] stockTicker={"AAPL", "GOOG", "MSFT"};
    double[] stockPrice={138.96, 830.63, 64.01};
    int[] shares={5, 2, 10};
    double[] percentChange={0.59, 0.55, 1.43};

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        getActivity().setTitle("Portfolio");
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.portfolio_layout, container, false);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.portfolio_layout);

        portfolioList = (ListView) findViewById(R.id.portfolioListView);

        //ADAPTER
        ListAdapter adapter = new portfolioListAdapter(this, stockTicker, stockPrice, shares, percentChange);
        portfolioList.setAdapter(adapter);
    }
}

0 个答案:

没有答案