小编sim*_*ed.的帖子

片段中的findViewById

我试图在片段中创建一个ImageView,它将引用我在片段的XML中创建的ImageView元素.但是,该findViewById方法仅在扩展Activity类时才有效.无论如何,我还可以在片段中使用它吗?

public class TestClass extends Fragment {
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        ImageView imageView = (ImageView)findViewById(R.id.my_image);
        return inflater.inflate(R.layout.testclassfragment, container, false);
    }
}
Run Code Online (Sandbox Code Playgroud)

findViewById方法有一个错误,表明该方法是未定义的.

android android-imageview android-fragments findviewbyid

975
推荐指数
23
解决办法
56万
查看次数

Android标签操作栏

我正在尝试3.0的android操作栏,我参考

http://www.youtube.com/watch?v=gMu8XhxUBl8

代码TabsActivity如下:

package com.test.actionbar;

import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.app.Fragment; 
import android.app.FragmentTransaction;
import android.os.Bundle;

public class TabsActivity extends Activity{

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ActionBar bar = getActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    ActionBar.Tab tabA = bar.newTab().setText("A Tab");
    ActionBar.Tab tabB = bar.newTab().setText("B Tab");
    ActionBar.Tab tabC = bar.newTab().setText("C Tab");

    Fragment fragmentA = new AFragmentTab();
    Fragment fragmentB = new BFragmentTab();
    Fragment fragmentC = new CFragmentTab();

    tabA.setTabListener(new MyTabsListener(fragmentA));
    tabB.setTabListener(new MyTabsListener(fragmentB));
    tabC.setTabListener(new MyTabsListener(fragmentC));

    bar.addTab(tabA);
    bar.addTab(tabB);
    bar.addTab(tabC);

}

protected class MyTabsListener implements …
Run Code Online (Sandbox Code Playgroud)

tabs android runtimeexception android-3.0-honeycomb android-actionbar

6
推荐指数
1
解决办法
3万
查看次数

Android操作栏 - 使用标签

我正在尝试在Android上创建一个标签操作栏,但我在遵循教程时似乎遇到了问题.他们通常会拥有未显示的资源,我也不太确定它们是什么导致我无法像在教程中那样编译项目.有人可以帮助我解决这个问题.谢谢.

tabs android android-actionbar

5
推荐指数
2
解决办法
2万
查看次数