ListView 将显示联系人。
选项:
一键式模式。如果用户单击一个项目(仅显示 TextView),应用程序将启动一个新活动(联系人资料)。
2-选择模式。如果用户从菜单或操作栏项目中选择添加到联系人,则列表视图将更改为选择模式(每个项目的文本视图 + 复选框)。
1-如何隐藏和显示复选框?
2-如何应对事件?
编码:
Activity的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/screen_background"
android:orientation="vertical" >
<SearchView
android:id="@+id/search_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapWords"
android:iconifiedByDefault="false" >
</SearchView>
<View
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="#000000" />
<ListView
android:id="@+id/listview_Menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:choiceMode="singleChoice" >
</ListView>
</LinearLayout>
列表视图项目布局:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:id="@+id/listview_checkbox_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/listview_textview_item"
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center"
android:textColor="#fefefe"
android:textSize="25sp" >
</TextView>
</LinearLayout>
活动类
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_view_screen);
String[] contacts = {"aaaa aaa", "bbbb bbbb" ,"ccccccc" ,"ddddd dddd" ,"ffffff ffffff"};
final ArrayAdapter<String> adapt =
new ArrayAdapter<String>( this, R.layout.list_view_item,
R.id.listview_textview_item,items);
ListView menuList = (ListView) findViewById(R.id.listview_Menu);
menuList.setAdapter(adapt);
menuList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View itemClicked,
int position, long id) {
// TODO Auto-generated method stub
startActivity(new Intent(this,
ContactProfile.class));
}
});
menuList.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}