注意添加application android:name="YourAppName"
public class YourAppName extends Application { private List<Item> mItems; @Override public void onCreate() { super.onCreate(); mItems = getYourItemList(); } public List<Item> getItems() { return mItems; }}

public class DetailActivity extends Activity {  private YourAppName mApp;  private ImageButton mNextButton;  private ImageButton mBackButton;  private TextView mTitle;  private int mIndex;  @Override  public void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.your_layout);    mApp = (YourAppName) getApplication();    /*This index should come from the intent */    mIndex = 2;     getWidgets();    populateWidgets();  }  private void getWidgets() {    mNextButton = (ImageButton)findViewById(R.id.next);    mTitle = (TextView)findViewById(R.id.title);    /* other findViewById */    mNextButton.setOnClickListener(new OnClickListener() {        public void onClick(View v) {           mIndex++; /*Notice that this will get a NPE.                     You need to place a better logic here */           populateWidgets();        }    });  }  private void populateWidgets() {    Item item = mApp.getItemList().get(mItem);    mTitle.setText(item.getName());  }}

更多相关文章

  1. Android(安卓)Jetpack Compose 之 Text
  2. Android(安卓)TextView 给文本中指定片段添加自定义点击事件
  3. Android(安卓)M 去除抽屉模式
  4. Android在程序中动态生成控件,动态布局
  5. [Android(安卓)Pro] Notification的使用
  6. android添加各种权限整理
  7. android ScrollView--Linearlayout可以上下拖动
  8. Android(安卓)Fragment页打开相册
  9. 启动 flutter项目时报Could not find com.android.tools.build:g

随机推荐

  1. android system setup and building (1)
  2. Android应用开发相关下载资源(2014/12/14
  3. 转 Android是什么?
  4. Android中TextVIew一些属性
  5. Android(安卓)layout_margin 无效的解决
  6. Android蓝牙开发浅析
  7. android:inputType标签
  8. Android(安卓)EditText属性
  9. Android(安卓)资源文件中@、@android:typ
  10. android:launchMode="singleTask" intent