在android中使用listview

use*_*066 1 android listview screen add

我正在制作一个需要使用的Android应用程序ListView.我想添加一个菜单按钮,上面写着"添加到列表",一旦该菜单按钮用户按下,它会弹出一个包含一个popupwindow TextView,EditText和两个Buttons,"确定"和"取消".一旦用户按下"确定",EditText应将其中的文本添加到ListView.取消Button很明显.我也希望能够长按一个ListView项目来打开一个包含删除的弹出窗口Button.我想ListView用XML 设计屏幕.我怎么能这样做??? 请帮助我,并提前感谢!我到目前为止使用此代码:

ListView活动:

public class NotesActivity extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}
Run Code Online (Sandbox Code Playgroud)

主屏幕XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
android:orientation="vertical" >








<ListView
    android:id="@+id/list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

</ListView>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

Jer*_*y D 8

  1. 您必须创建包含listView的布局.

  2. 您必须创建与列表视图的一行对应的xml lyout.

  3. 您必须创建一个适配器,它将填充数据以插入listView

  4. 您必须在按钮上创建onClickListener才能在列表中添加数据

  5. 如果您使用的是ArrayAdapter或CursorAdapter,请将您创建的新项目添加到列表或适配器使用的光标(notifyDataSetChanged()自动调用),以便适配器更新列表视图

资料来源:http: //developer.android.com/resources/tutorials/views/hello-listview.html

上一个主题:Android应用中的动态ListView