android 添加CheckBox单击事件编译通过,但模拟器中报错,这是为什么? 本帖最后由 ztwz 于 2011-01-16 12:32:14 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 -_-b偶太菜了,偶搜索了一下BaseAdapter的类用法,学着写了一个继承BaseAdapter的,连布局都没加载出来。呃,不论哪种方法都没成功,楼上的可否写个deom给我学习一下,我要的效果就是ListView中点击CheckBox进入他的单击事件! 解决问题,在Item的Click事件中添加CheckBox的Click监听事件代码如下package ztwz.test;import java.util.ArrayList;import java.util.HashMap; import android.app.Activity; import android.graphics.Color;import android.os.Bundle; import android.view.ContextMenu;import android.view.LayoutInflater;import android.view.MenuItem;import android.view.View; import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.CompoundButton;import android.view.ContextMenu.ContextMenuInfo;import android.view.View.OnCreateContextMenuListener;import android.widget.*;import android.widget.AdapterView.OnItemClickListener;import android.widget.CompoundButton.OnCheckedChangeListener;public class testActivity extends Activity { /** Called when the activity is first created. */ private MyAdapter myAdapter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ArrayList<HashMap<String,Object>> listitem=new ArrayList<HashMap<String,Object>>(); myAdapter=new MyAdapter(); CheckBox chb=(CheckBox)findViewById(R.id.chb); ListView mylistview =(ListView) findViewById(R.id.MyListView); HashMap<String,Object> map =new HashMap<String,Object>(); map.put("Title", "自动横屏"); map.put("ItemText", "自动感应重力横竖屏"); listitem.add(map); SimpleAdapter listitemAdapter = new SimpleAdapter(this, listitem, R.layout.mylistviewstyle, new String[]{"Title","ItemText"}, new int [] {R.id.topTextView,R.id.bottomTextView} ); mylistview.setAdapter(listitemAdapter); //mylistview单击监听 mylistview.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { CheckBox chb=(CheckBox)findViewById(R.id.chb); chb.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener(){ @Override public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) { if(isChecked) { Toast.makeText(testActivity.this, "重力感应自动横屏开启",1000).show(); } else { Toast.makeText(testActivity.this, "重力感应自动横屏关闭",1000).show(); } } }); } }); }} AudioRecord 初始化失败求教! android如何在绘制楼盘表 锁定横屏的问题,关于surfaceView,大虾们帮帮忙 点击对话框外面的部分,对话框会消失,这个事件能否获取到? andoird源码修改问题 Gson 解析数据问题 !!! 求解决阿!! MTK短信源码 谁有android自定义控件的学习资料啊? 多个图片uri怎么传入webview的onReceiveValue那里呢? android LocationManaget中的CurrentLocation(String)哪去了? Git 2.2源码的问题 大家帮帮忙 急死了
偶太菜了,偶搜索了一下BaseAdapter的类用法,学着写了一个继承BaseAdapter的,连布局都没加载出来。
呃,不论哪种方法都没成功,楼上的可否写个deom给我学习一下,我要的效果就是ListView中点击CheckBox进入他的单击事件!
代码如下package ztwz.test;import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CompoundButton;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnCreateContextMenuListener;
import android.widget.*;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.CompoundButton.OnCheckedChangeListener;public class testActivity extends Activity {
/** Called when the activity is first created. */ private MyAdapter myAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayList<HashMap<String,Object>> listitem=new ArrayList<HashMap<String,Object>>();
myAdapter=new MyAdapter();
CheckBox chb=(CheckBox)findViewById(R.id.chb);
ListView mylistview =(ListView) findViewById(R.id.MyListView);
HashMap<String,Object> map =new HashMap<String,Object>();
map.put("Title", "自动横屏");
map.put("ItemText", "自动感应重力横竖屏");
listitem.add(map);
SimpleAdapter listitemAdapter = new SimpleAdapter(this,
listitem,
R.layout.mylistviewstyle,
new String[]{"Title","ItemText"},
new int [] {R.id.topTextView,R.id.bottomTextView}
);
mylistview.setAdapter(listitemAdapter);
//mylistview单击监听
mylistview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
CheckBox chb=(CheckBox)findViewById(R.id.chb);
chb.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
if(isChecked)
{
Toast.makeText(testActivity.this, "重力感应自动横屏开启",1000).show();
}
else
{
Toast.makeText(testActivity.this, "重力感应自动横屏关闭",1000).show();
}
}
});
}
});
}
}