Skip to content Skip to sidebar Skip to footer

Android-button's Clickevent Of Listview Using Baseadapter

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 r

Solution 1:

privateContext context;

publicListViewAdapter(Context context, String[] dateValues,String[] creditAmountValues,String[] closingBalanceValues,String[] currentAmountValues) 
{
    super(context, R.layout.transactionlayout, dateValues);
    this.context = context;

}

 @OverridepublicViewgetView(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(newOnClickListener() {

        @OverridepublicvoidonClick(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.

Solution 2:

set the tag for each view in get view method by setTag()

@Overridepublic View getView(int position, View convertView, ViewGroup parent) {


        if (convertView == null) {                            
            LayoutInflaterinflater= context.getLayoutInflater();
            convertView = inflater.inflate(.....);
        } 

        ur_view= (views) convertView.findViewById(R.id.....);
                ur_view.setTag(position);

        ur_view.setOnClickListener(newView.OnClickListener() {
            publicvoidonClick(View v) {
                //do something
            }
        }); 

It will work

Solution 3:

Solution 4:

Try this, may be it will solve your problem.

btnAdd.setOnClickListener(newOnClickListener() {

    @OverridepublicvoidonClick(View arg0) {
        // TODO Auto-generated method stubIntegerindex= (Integer) arg0.getTag();

        Toast.makeText(context, "ADD", Toast.LENGTH_LONG).show();
        Intentintent=newIntent(context,MaterDeviceFormActivity.class);
        intent.putExtra("button","add");
        intent.putExtra("device_address", strDviceAddess[index]);
        context.startActivity(intent);
    }
});

btnUpdate.setOnClickListener(newOnClickListener() {

    @OverridepublicvoidonClick(View arg0) {
        // TODO Auto-generated method stubIntegerindex= (Integer) arg0.getTag();

        Toast.makeText(context, "UPDATE", Toast.LENGTH_LONG).show();
        Intentintent=newIntent(context,MaterDeviceFormActivity.class);
        intent.putExtra("button","update");
        intent.putExtra("device_address", strDviceAddess[index]);
        context.startActivity(intent);
    }
});

btnDelete.setOnClickListener(newOnClickListener() {

    @OverridepublicvoidonClick(View arg0) {
        // TODO Auto-generated method stubIntegerindex= (Integer) arg0.getTag();

        Toast.makeText(context, "DELETE", Toast.LENGTH_LONG).show();
        Intentintent=newIntent(context,MaterDeviceFormActivity.class);
        intent.putExtra("button","delete");
        intent.putExtra("device_address", strDviceAddess[index]);
        context.startActivity(intent);
    }
});

Solution 5:

You can use the button listener inside the the adapter but the only item to register it will be the last item drawn (ie the one immediately off the list). You need to tell the button listener which item it has been clicked on. In my case I just passed in the position and used that to load any associated info needed to manipulate the list item.

Post a Comment for "Android-button's Clickevent Of Listview Using Baseadapter"