打开列表视图时,点击按钮 [英] open listview when click button
问题描述
我想要做的事,当我点击按钮,他将openfor我像列表视图与所有联系人的名字在我的手机......我该怎么办呢?
我知道如何让我的手机中的所有联系人的姓名,并把它们放到字符串数组,但我怎么能打开一个新的窗口与所有联系人的名称列表视图,当我点击按钮?
i want to do something that when i click on button he will openfor me something like listview with the name of all the contacts in my phone...how can i do it? i know how to get the names of all the contacts in my phone and put them into string array,however how can i open a new windows with a listview of all the contacts name when i click on button?
感谢
推荐答案
在你的第一个活动,当你点击按钮:
In your first Activity when you click on button:
startActivity(new Intent(this, ContactsActivity.class));
然后在您的ContactsActivity:
Then in your ContactsActivity:
public class ContactsActivity extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.contacts_view);
ListAdapter adapter = createAdapter();
setListAdapter(adapter);
}
/**
* Creates and returns a list adapter for the current list activity
* @return
*/
protected ListAdapter createAdapter()
{
// List with strings of contacts name
contactList = ... someMethod to get your list ...
// Create a simple array adapter (of type string) with the test values
ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, contactList);
return adapter;
}
}
您ContactsActivity(命名为contacts_view.xml)XML文件:
XML file for your ContactsActivity (name it to contacts_view.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Empty set"
/>
</LinearLayout>
这篇关于打开列表视图时,点击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!