开发者

sharing ListView between classes

I have a ListView code in a class but I want to show the list into another class. How can I do it?

public class listar_teste extends ListActivity 
{
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  String[] names = new String[] { "Linux", "Windows7", "Eclipse", "Suse",
            "Ubuntu", "Solaris", "Android", "iPhone" };
  setListAdapter(new ArrayAdapter<String>(this, R.layout.lista_categorias, names));

  ListView lv = getListView();
  lv.setTextFilterEnabled(true);
  lv.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view,
        int position, long id) {
      // When clicked, show a toast with the TextView text
      Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
          Toast.LENGTH_SHORT).show();
    }
  });
}

}

I want to 开发者_如何学运维put in a ListView from another class..


You should be able to instantiate your specialized version of ListActivity wherever you use a normal ListActivity. You can even use it in a layout by specifying the full package in the tag name.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜