如何更改视图以及应该放置的位置?

时间:2011-07-06 17:28:27

标签: android listview view

我想创建一个带有“添加新记录”按钮的ListView。我已经为我的ListVIew创建了自定义适配器,我有新记录的形式(我的意思是xml),我在按钮上设置了onClick操作。

现在我想知道如何改变观点和最重要的问题。更改视图后会发生什么?

例如,我有onCreate功能:

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

    NewserDatabase ndb = new NewserDatabase(this);

    DataInput di = new DataInput();
    ArrayList news = di.getNews();

    NewsArrayAdapter naa = new NewsArrayAdapter(NewserActivity.this, R.layout.row, news);
    setListAdapter(naa);
    ListView lv = getListView();

    lv.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView parent, View view,
      int position, long id) {
    Log.i("testy", "I Clicked on Row " + position + " and it worked!");
  }
});

}

现在我应该以什么方法管理新视图?它应该在onItemClick中设置吗?活动类应该改变吗?

//编辑-----------

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

    NewserDatabase ndb = new NewserDatabase(this);

    DataInput di = new DataInput();
    ArrayList news = di.getNews();

    NewsArrayAdapter naa = new NewsArrayAdapter(NewserActivity.this, R.layout.row, news);
    setListAdapter(naa);
    ListView lv = getListView();

    lv.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView parent, View view,
      int position, long id) {
        Log.i("testy", "I Clicked on Row " + position + " and it worked!");
        Intent formIntent = new Intent(NewserActivity.this, NewsAddActivity.class);
        NewserActivity.this.startActivity(formIntent);
  }
});

}

0 个答案:

没有答案