2011-01-07 73 views
27

我有一個佈局,其中包含手機的聯繫人信息。當我點擊選項菜單時,我需要在該屏幕上顯示可見的edittext。我已經做了。但是有一個問題是編輯文本的高度在屏幕上被隱藏時會佔用。如何刪除通過編輯文本所佔用的空間,而其在屏幕(佈局)..我的代碼如下隱藏EditText並通過單擊菜單使其可見

我的XML給出無形是:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:paddingLeft="10dp" 
    android:paddingRight="10dp"> 

    <ListView android:id="@id/android:list" android:layout_width="fill_parent" 
     android:layout_height="fill_parent" android:layout_weight="1" 
     android:drawSelectorOnTop="false"> 
    </ListView> 

    <TextView android:id="@id/android:empty" android:layout_width="fill_parent" 
     android:layout_height="fill_parent" android:text="No Entries available"> 
    </TextView> 




    <TableRow android:id="@+id/TableRow001" 
     android:layout_width="wrap_content" android:background="#C0C0C0" 
     android:layout_height="wrap_content"> 

     <EditText android:id="@+id/NumberEditText01" 

      android:layout_width="wrap_content" 
      android:paddingLeft="20dip" 
      android:layout_height="wrap_content"> 
     </EditText> 

     <Button android:layout_width="wrap_content" android:id="@+id/callNow01" 
      android:layout_height="wrap_content" 
      android:text="Call now" 
      > 
     </Button> 

    </TableRow> 
</LinearLayout> 

和類:

public class ListContacts extends ListActivity { 

    TableRow tableRow; 
    EditText phoneNumber; 
    Button callNow; 

    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     // Associate the xml with the activity 
     setContentView(R.layout.activitylist); 
     tableRow = (TableRow) findViewById(R.id.TableRow001); 
     tableRow.setVisibility(View.INVISIBLE); 


     phoneNumber = (EditText) findViewById(R.id.NumberEditText01); 
     phoneNumber.setVisibility(View.INVISIBLE); 
     phoneNumber.setKeyListener(DialerKeyListener.getInstance()); 

     callNow = (Button) findViewById(R.id.callNow01); 
     callNow.setVisibility(View.INVISIBLE); 
    } 


    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     switch (item.getItemId()) { 

      case FIRST: 
       tableRow.setVisibility(View.VISIBLE); 
       phoneNumber.setVisibility(View.VISIBLE); 
       callNow.setVisibility(View.VISIBLE); 
       break; 
     } 
    } 
} 

回答

74

嘗試phoneNumber.setVisibility(View.GONE);

+0

非常感謝你indyfromoz。它的工作正常。 – jennifer 2011-01-07 04:51:24