问题描述
我使用的列表视图随着包含的ImageView,TextView中和3键(插入,更新,删除)的要求是自定义适配器是叫广播接收器内的每个时间,直到IntentFilter的匹配,我也自定义适配器设置onclicklistener按钮的底座适配器的getView方法。
的问题是,列表视图按钮,只有最后一排只有clickable..But我希望所有行的所有按钮必须点击。
任何人都可以给我建议或任何想法,我可以如何进行该问题。
公开查看getView(最终诠释的立场,观点来看,一个ViewGroup父){
// TODO自动生成方法存根
POS =位置;
如果(查看== NULL)
{
LayoutInflater充气=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
鉴于= inflater.inflate(R.layout.device_name,父母,假);
}
TextView的text_view =(TextView中)view.findViewById(R.id.textview_deviceName);
ImageView的image_view =(ImageView的)view.findViewById(R.id.imageView1);
text_view.setText(strDeviceName [位置]);
如果(strMajorDevice [位置] .equalsIgnoreCase(手机))
{
image_view.setImageResource(int_image [0]);
}
其他
{
image_view.setImageResource(int_image [1]);
}
btnAdd =(按钮)view.findViewById(R.id.btn_add);
为btnUpdate =(按钮)view.findViewById(R.id.btn_update);
btnDelete =(按钮)view.findViewById(R.id.btn_delete);
btnAdd.setOnClickListener(本);
btnUpdate.setOnClickListener(本);
btnDelete.setOnClickListener(本);
返回查看;
}
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
如果(V == btnAdd)
{
Toast.makeText(背景下,ADD,Toast.LENGTH_LONG).show();
意向意图=新的意图(背景下,MaterDeviceFormActivity.class);
intent.putExtra(按钮,增加);
intent.putExtra(DEVICE_ADDRESS,strDviceAddess [POS]);
context.startActivity(意向);
}
否则,如果(V ==为btnUpdate)
{
Toast.makeText(上下文中,数据库,Toast.LENGTH_LONG).show();
意向意图=新的意图(背景下,MaterDeviceFormActivity.class);
intent.putExtra(按钮,更新);
intent.putExtra(DEVICE_ADDRESS,strDviceAddess [POS]);
context.startActivity(意向);
}
否则,如果(V == btnDelete)
{
Toast.makeText(上下文,DELETE,Toast.LENGTH_LONG).show();
意向意图=新的意图(背景下,MaterDeviceFormActivity.class);
intent.putExtra(键,删除);
intent.putExtra(DEVICE_ADDRESS,strDviceAddess [POS]);
context.startActivity(意向);
}
}
私人上下文的背景下;
公共ListViewAdapter(上下文的背景下,的String [] dateValues,字符串[] creditAmountValues,字符串[] closingBalanceValues,字符串[] currentAmountValues)
{
超(背景下,R.layout.transactionlayout,dateValues);
this.context =背景;
}
@覆盖
公共查看getView(最终诠释的立场,观点convertView,ViewGroup中父){
LayoutInflater充气=(LayoutInflater)上下文
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
查看rowView = inflater.inflate(R.layout.transactionlayout,父母,假);
((按钮)rowView.findViewById(R.id.transactions_historyButtonID))。setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
Toast.makeText(上下文,+的位置,4000).show();
}
});
返回rowView;
}
获得使用用打气筒行视图。这是工作。让我知道如果u有任何的怀疑。
I am using Listview With custom Adapter which contain imageview,textview and 3 button (insert,update,delete)requirement is that custom adapter is call every time inside BROADCAST receiver until intentfilter matched and i also set onclicklistener of button in getView method of base adapter.
The problem is that only the last row of listview button is only clickable..But i want all the button of all row must clickable.
Can anybody give me suggestion or any idea how I can proceed for that problem.
public View getView(final int position, View view, ViewGroup parent) {
// TODO Auto-generated method stub
pos=position;
if(view==null)
{
LayoutInflater inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view=inflater.inflate(R.layout.device_name, parent, false);
}
TextView text_view=(TextView)view.findViewById(R.id.textview_deviceName);
ImageView image_view=(ImageView)view.findViewById(R.id.imageView1);
text_view.setText(strDeviceName[position]);
if(strMajorDevice[position].equalsIgnoreCase("phone"))
{
image_view.setImageResource(int_image[0]);
}
else
{
image_view.setImageResource(int_image[1]);
}
btnAdd=(Button)view.findViewById(R.id.btn_add);
btnUpdate=(Button)view.findViewById(R.id.btn_update);
btnDelete=(Button)view.findViewById(R.id.btn_delete);
btnAdd.setOnClickListener(this);
btnUpdate.setOnClickListener(this);
btnDelete.setOnClickListener(this);
return view;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v==btnAdd)
{
Toast.makeText(context, "ADD", Toast.LENGTH_LONG).show();
Intent intent = new Intent(context,MaterDeviceFormActivity.class);
intent.putExtra("button","add");
intent.putExtra("device_address", strDviceAddess[pos]);
context.startActivity(intent);
}
else if(v==btnUpdate)
{
Toast.makeText(context, "UPDATE", Toast.LENGTH_LONG).show();
Intent intent = new Intent(context,MaterDeviceFormActivity.class);
intent.putExtra("button","update");
intent.putExtra("device_address", strDviceAddess[pos]);
context.startActivity(intent);
}
else if(v==btnDelete)
{
Toast.makeText(context, "DELETE", Toast.LENGTH_LONG).show();
Intent intent = new Intent(context,MaterDeviceFormActivity.class);
intent.putExtra("button","delete");
intent.putExtra("device_address", strDviceAddess[pos]);
context.startActivity(intent);
}
}
private Context context;
public ListViewAdapter(Context context, String[] dateValues,String[] creditAmountValues,String[] closingBalanceValues,String[] currentAmountValues)
{
super(context, R.layout.transactionlayout, dateValues);
this.context = context;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.transactionlayout, parent, false);
((Button)rowView.findViewById(R.id.transactions_historyButtonID)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, ""+position, 4000).show();
}
});
return rowView;
}
get the use of row view using inflater. this is working. let me know if u have any doubts.
这篇关于ListView控件的使用BaseAdapter Android系统按钮的clickevent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!