package com.example.abbiapplock;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.ActionBar;
import android.app.Activity;
import android.app.LauncherActivity.ListItem;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnCreateContextMenuListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
public class ChooseProtectTypeActivity extends Activity{
String[] itemname = {"App Locker","File Protection"};
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
ActionBar actionbar = getActionBar();
actionbar.setDisplayShowTitleEnabled(true);
// actionbar.setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.choose_protect_type);
final ListView list = (ListView)findViewById(R.id.chooseprotecttype_list);
ArrayList<HashMap<String,Object>> listItem = new ArrayList<HashMap<String,Object>>();
for(int i=0;i<2;i++)
{
HashMap<String,Object> map = new HashMap<String,Object>();
map.put("itemtext", itemname[i]);
map.put("itemimage", R.id.itemimage);
listItem.add(map);
}
SimpleAdapter listItemAdapter = new SimpleAdapter(this,listItem,
R.layout.chooseprotecttype_detail,
new String[]{"itemimage","itemtext"},
new int[]{R.id.itemimage,R.id.itemtext});
list.setAdapter(listItemAdapter);
list.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
setTitle("已选" + itemname[arg2]);
//只能选单个
final int count = list.getChildCount();
for (int i = 0; i < count; i++) {
final RelativeLayout layout = (RelativeLayout) list.getChildAt(i);
final int c = layout.getChildCount();
for (int j = 0; j < c; j++) {
final View view = layout.getChildAt(j);
if (view instanceof CheckBox) {
if(i == arg2)
((CheckBox) view).setChecked(true);
else
((CheckBox) view).setChecked(false);
break;
}
}
}
// 随意选择
// final RelativeLayout layout = (RelativeLayout)list.getChildAt(arg2);
// final int c = layout.getChildCount();
// for(int j = 0;j<c;j++)
// {
// final View view = layout.getChildAt(j);
// if(view instanceof CheckBox)
// {
// ((CheckBox)view).setChecked(true);
// break;
// }
// }
Log.i("Abbi","已点选" + arg2 + "/" + arg1 + "/" + arg3);
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch(item.getItemId())
{
case android.R.id.home:
Log.i("Abbi","item.getItemId0 = home");
Intent i = new Intent(this,MainActivity.class);
startActivity(i);
break;
default:
Log.i("Abbi","item.getItemId = default");
break;
}
return true;
}
// @Override
// public boolean onKeyDown(int keyCode, KeyEvent event)
// {
// if(keyCode == KeyEvent.KEYCODE_BACK){
// Intent myIntent = new Intent();
// myIntent = new Intent(this, MainActivity.class);
// startActivity(myIntent);
// this.finish();
// }
// return super.onKeyDown(keyCode, event);
// }
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
// TODO Auto-generated method stub
super.onCreateContextMenu(menu, v, menuInfo);
}
}
import java.util.ArrayList;
import java.util.HashMap;
import android.app.ActionBar;
import android.app.Activity;
import android.app.LauncherActivity.ListItem;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnCreateContextMenuListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
public class ChooseProtectTypeActivity extends Activity{
String[] itemname = {"App Locker","File Protection"};
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
ActionBar actionbar = getActionBar();
actionbar.setDisplayShowTitleEnabled(true);
// actionbar.setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.choose_protect_type);
final ListView list = (ListView)findViewById(R.id.chooseprotecttype_list);
ArrayList<HashMap<String,Object>> listItem = new ArrayList<HashMap<String,Object>>();
for(int i=0;i<2;i++)
{
HashMap<String,Object> map = new HashMap<String,Object>();
map.put("itemtext", itemname[i]);
map.put("itemimage", R.id.itemimage);
listItem.add(map);
}
SimpleAdapter listItemAdapter = new SimpleAdapter(this,listItem,
R.layout.chooseprotecttype_detail,
new String[]{"itemimage","itemtext"},
new int[]{R.id.itemimage,R.id.itemtext});
list.setAdapter(listItemAdapter);
list.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
setTitle("已选" + itemname[arg2]);
//只能选单个
final int count = list.getChildCount();
for (int i = 0; i < count; i++) {
final RelativeLayout layout = (RelativeLayout) list.getChildAt(i);
final int c = layout.getChildCount();
for (int j = 0; j < c; j++) {
final View view = layout.getChildAt(j);
if (view instanceof CheckBox) {
if(i == arg2)
((CheckBox) view).setChecked(true);
else
((CheckBox) view).setChecked(false);
break;
}
}
}
// 随意选择
// final RelativeLayout layout = (RelativeLayout)list.getChildAt(arg2);
// final int c = layout.getChildCount();
// for(int j = 0;j<c;j++)
// {
// final View view = layout.getChildAt(j);
// if(view instanceof CheckBox)
// {
// ((CheckBox)view).setChecked(true);
// break;
// }
// }
Log.i("Abbi","已点选" + arg2 + "/" + arg1 + "/" + arg3);
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch(item.getItemId())
{
case android.R.id.home:
Log.i("Abbi","item.getItemId0 = home");
Intent i = new Intent(this,MainActivity.class);
startActivity(i);
break;
default:
Log.i("Abbi","item.getItemId = default");
break;
}
return true;
}
// @Override
// public boolean onKeyDown(int keyCode, KeyEvent event)
// {
// if(keyCode == KeyEvent.KEYCODE_BACK){
// Intent myIntent = new Intent();
// myIntent = new Intent(this, MainActivity.class);
// startActivity(myIntent);
// this.finish();
// }
// return super.onKeyDown(keyCode, event);
// }
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
// TODO Auto-generated method stub
super.onCreateContextMenu(menu, v, menuInfo);
}
}