Skip to content Skip to sidebar Skip to footer

Multiple Clickable Items With Different Actions To Perform In Listfragment From Sqlite

I'm a beginner. I've a ListFragment where every element in the list contains three TextView and two different Buttons. Reading data from SQLite Database. Something like this: List

Solution 1:

For making the multiple clickables in your list row you have to include the below given code for the views/buttons in the XML:

android:clickable="true"android:focusable="false"android:focusableInTouchMode="true"

and for doing operation for single row you need to use custom adapters instead using SimpleCursorAdapter, here the example goes

publicclassCustomListAdapterextendsBaseAdapter
        {

            private Context mContext;
            String[] cursor;
            publicSMSListAdapter(Context context,String[] cur)
            {
                    super();
                    mContext=context;
                    cursor=cur;

            }

            publicintgetCount()
            {
                // return the number of records in cursorreturn cursor.length;
            }

            // getView method is called for each item of ListViewpublic View getView(int position,  View view, ViewGroup parent)
            {
                            // inflate the layout for each item of listViewLayoutInflaterinflater= (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                            view = inflater.inflate(R.layout.listview_each_item, null);



                            // get the reference of textViews
                            TextView textViewConatctNumber=(TextView)view.findViewById(R.id.textViewSMSSender);
                            TextView textViewSMSBody=(TextView)view.findViewById(R.id.textViewMessageBody);
    Button bt1=(Button)view.findViewById(R.id.btn1);

    bt1.setOnClickListner(newOnClickListener() {

                @OverridepublicvoidonClick(View view) {
}
});

                            // Set the Sender number and smsBody to respective TextViews
                            textViewConatctNumber.setText(senderNumber);
                            textViewSMSBody.setText(smsBody);


                            return view;
            }

            public Object getItem(int position) {
                // TODO Auto-generated method stubreturn position;
            }

            publiclonggetItemId(int position) {
                // TODO Auto-generated method stubreturn position;
            }
        }

Post a Comment for "Multiple Clickable Items With Different Actions To Perform In Listfragment From Sqlite"