English 中文(简体)
Populate ListView with Dynamic Array
原标题:Populate ListView with Dynamic Array
  • 时间:2012-01-12 10:28:27
  •  标签:
  • android

我有一个<代码>EditText盒子,以便用户能够输入姓名,然后点击Add,纽扣吨,并标明箱子,以便添加另一个名称。

我还有一个关于同一活动的,然后按<代码>中的名称排列。 Array。 问题是<代码>。 ListView dosen t 似乎有人居住。

因此,我尝试了一套精彩的指令-teststring,可参看下文,并填写ListView。 我的问题是,与<条码”合作的程度如何。 Array。 不得将其保留至<代码>。 Array 正确?

www.un.org/Depts/DGACM/index_spanish.htm 更新仅需要<条码>。 清单: Credit to @Lalit Poptani and @Jave

ArrayList<String> playerList = new ArrayList<String>();
ListView listview;
protected String[] teststring = {"Name 1", "Name 2"};

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.addremove);
ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, teststring);
ListView employeeList = (ListView) findViewById(R.id.namelistview);
employeeList.setAdapter(adapter);


Button confirm = (Button) findViewById(R.id.add);
confirm.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
EditText playername = (EditText) findViewById(R.id.userinput);
String name = playername.getText().toString();
playerList.add(name);
playername.setText("");

}});
最佳回答

页: 1 在增加新项目以更新新数据之后。

Notifies the attached observers that the underlying data has been changed and any View reflecting the data set should refresh itself.

问题回答

在您增加新数据之后,再补充名单,请打电话adapter.notificationDataSetChanged(。 本文将重述您的《名单》。

但是,在您的情形下,你把名单与Sting[]号拼凑起来,这样就能够积极工作,你必须给予<编码>的大小。 因此,我建议你把名单填入<代码>ArrayList,以便积极增加内容。

ListAdapter adapter = new ArrayAdapter<String>
                       (this, android.R.layout.simple_list_item_1,playerList);




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签