lundi 4 mai 2015

How to set visibility of checkbox and button in android?

I am able to get my phone contact on list view with name.On right side of list view I have added a button like invite button.Now I want when I click on this button then this button disappear and the check box is appeared with tick mark.

I try lots but I am unable to do this.please help me to solve this problem.

public class FriendListActivity extends Activity {

        SimpleCursorAdapter adapter;
        ListView lvContacts;
        Button b1;
        CheckBox chk;

        @SuppressWarnings("deprecation")
        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                this.requestWindowFeature(Window.FEATURE_NO_TITLE);
                setContentView(R.layout.activity_friend_listview);
                

                lvContacts = (ListView) findViewById(R.id.lv_friend_list);
                ContentResolver cr = getContentResolver();

                // Read Contacts
                Cursor c = cr.query(ContactsContract.Contacts.CONTENT_URI,
                new String[] { ContactsContract.Contacts._ID,ContactsContract.Contacts.DISPLAY_NAME }, null, null,
                                null);

                // Attached with cursor with Adapter
                adapter = new SimpleCursorAdapter(this, R.layout.activity_phonecontact,
                                c, new String[] { ContactsContract.Contacts.DISPLAY_NAME },
                                new int[] { R.id.tv_name });
                       lvContacts.setAdapter(adapter);
                       
                       b1 = (Button)findViewById(R.id.btn_invite);
                       
                       
                       b1.setOnClickListener(new OnClickListener() {
                 
                                            @Override
                                            public void onClick(View arg0) {
                                            b1.setVisibility(View.GONE);    
                                            chk.setVisibility(View.VISIBLE);
                                        } 
                                        });
                             }
                         
                       
                     }
        
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    
    <ImageView
        android:id="@+id/img_frnd_list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/include1"
        android:background="@null"
        android:paddingLeft="10dp"
        android:paddingTop="10dp"
        android:contentDescription="@string/imageView_contact_image"
        android:src="@drawable/contactimage" />

    <TextView
        android:id="@+id/tv_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/include1"
        android:layout_toRightOf="@+id/img_frnd_list"
        android:paddingLeft="10dp"
        android:paddingTop="35dp"
        android:textSize="@dimen/contact_text_size"
        android:text="@string/Contact_Name" />
    
    
    
    
    
    <Button
         android:text="Play" 
         android:id="@+id/btn_invite" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:paddingTop="80dp"
        android:visibility="visible"
        android:layout_below="@+id/include1"
        android:paddingRight="10dp" 
   >
</Button>

    <CheckBox
        android:id="@+id/chk_frnd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
       android:visibility="gone"
        android:layout_alignParentRight="true"
        android:paddingTop="80dp"
        android:layout_below="@+id/include1"
        android:paddingRight="10dp" />
    
    


</RelativeLayout>



Aucun commentaire:

Enregistrer un commentaire