问题描述
我提出,需要使用的ListView
Android应用程序。我想添加一个菜单按钮,上面写着添加到列表,一旦该菜单按钮,用户presses,它会弹出包含popupwindow一个的TextView
,的EditText
和两个按钮
,确定和取消。一旦用户presses确定后,的EditText
应加入的ListView
中的文本。而取消按钮
是显而易见的。我也希望能够在一个的ListView
项长preSS打开包含删除按钮popupwindow
。我想设计使用XML屏的ListView。我怎样才能让这一切成为可能?请帮助我,感谢这么多提前!我用这code迄今:
ListView的活动:
公共类NotesActivity扩展ListActivity {
/ **当第一次创建活动调用。 * /
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
}
主屏XML:
<?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:背景=@绘制/背景
机器人:方向=垂直>
< ListView控件
机器人:ID =@ + ID /列表
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT>< /&的ListView GT;< / LinearLayout中>
-
您必须创建一个包含ListView控件的布局。
-
您必须创建lyout对应的列表视图中一行的XML。
-
您必须创建一个适配器,将数据填入你的ListView插入
-
您必须对您的按钮,在列表中添加数据创建一个onClickListener
-
如果您使用的是ArrayAdapter或CursorAdapter的,添加新
项目创建到你的适配器使用的列表或光标
(notifyDataSetChanged()
被自动调用),所以你的适配器将更新
列表视图
来源:
previous话题p>
I am making an android application that needs to use a ListView
. I want to add a menubutton that says "Add to list" and once the user presses that menubutton, it pops up a popupwindow containing a TextView
, EditText
and two Buttons
, "Ok" and "Cancel". Once the user presses "Ok", the text inside the EditText
should be added to the ListView
. And the cancel Button
is obvious. I also want to be able to long press on a ListView
item to open a popupwindow containing a delete Button
. I want to design the ListView
screen using XML. How can i make this possible??? Please help me and thanks SO much in advance! I am using this code so far:
ListView activity:
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);
}
Main screen 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>
You have to create a layout containing a listView.
You have to create an xml lyout corresponding to one row of your list view.
You have to create an adapter which will populate data to insert in your listView
You have to create an onClickListener on your button to add data in your list
If you are using an ArrayAdapter or a CursorAdapter, add the newitem you created to the list or the cursor used by your adapter and(
notifyDataSetChanged()
is automatically called), so your adapter will update thelistview
Source :http://developer.android.com/resources/tutorials/views/hello-listview.html
Previous topic on it : Dynamic ListView in Android app
这篇关于在Android的应用列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!