2012-05-30 49 views
1

我的佈局是這樣的:每行可點擊像android鬧鐘一樣的可點擊佈局?

--------------------------- 
    stuff from database 
--------------------------- 
next entry from database 
--------------------------- 
next entry 
-------------------------- 

我喜歡做的是:觀「從數據庫的東西」是要對鬧鐘時間等信息報警第一部分熄滅,它可以點擊,部分視圖的開啓也是可點擊的,但是應該能夠從同一行的旁邊的行中獲取信息,因爲它需要信息,比如說警報ID。我該如何做?


stuff from database  | turn on 
-------------------------------------- 
next entry from database | turn on 
-------------------------------------- 
next entry     | turn on 
--------------------------------------- 

這是代碼我有:

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/widget38" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_marginLeft="10dip" 
     android:layout_marginRight="10dip" 
     android:orientation="vertical" > 

     <TextView 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/text1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="center_vertical" 
      android:textSize="25sp" /> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" > 


      <TextView 
       android:id="@+id/text2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textSize="30sp" /> 
    <TextView 
       android:id="@+id/text3" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text=" - " 
       android:textSize="30sp" /> 
      <TextView 
       android:id="@+id/text4" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textSize="30sp" /> 

      <CheckBox 
        android:text="" 
     android:id="@+id/list_checkbox" 
     android:layout_marginLeft="20dp" 
     android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
     android:checked="false" 
     android:focusable="false" 
android:focusableInTouchMode="false" 
     /> 

</LinearLayout> 



    <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" > 
      <TextView 
       android:id="@+id/text5" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textSize="15sp" /> 

     </LinearLayout> 

    </LinearLayout> 

更新

public void addListenerOnButton() { 

    final ToggleButton toggleButton1 = (ToggleButton) findViewById(R.id.toggleButton1); 
    //toggleButton2 = (ToggleButton) findViewById(R.id.toggleButton2); 
    Button btnDisplay = (Button) findViewById(R.id.toggleButton1); 

    btnDisplay.setOnClickListener(new OnClickListener() { 

     public void onClick(View v) { 

      // StringBuffer result = new StringBuffer(); 
      // result.append("toggleButton1 : ").append(toggleButton1.getText()); 
    //  result.append("\ntoggleButton2 : ").append(toggleButton1.getText()); 

     // Toast.makeText(MyAndroidAppActivity.this, result.toString(), 
      //Toast.LENGTH_SHORT).show(); 

     } 

    }); 

} 

我用噸

protected void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main_activity); 


     databaseHelper = new DatabaseStore(this); 
     databaseHelper.open(); 
     ListViewData(); 

     registerForContextMenu(getListView()); 
    } 


    private void ListViewData(){ 
     Cursor MainPageCursor = databaseHelper.fetchAllReminders(); 
     startManagingCursor(MainPageCursor); 


     String[] empty = new String[] { DatabaseStore.MUTE_TITLE, DatabaseStore.START_KEY_TIME, DatabaseStore.END_KEY_TIME, DatabaseStore.COVERT_DAYS }; 



      int[] notempty = new int[]{R.id.text1,R.id.text2, R.id.text4, R.id.text5}; 
      SimpleCursorAdapter mainPageList = new SimpleCursorAdapter(this, R.layout.editinfo_row,MainPageCursor, empty, notempty); 
      setListAdapter(mainPageList); 


      } 

protected void onListItemClick(ListView l, View v, int position, long id){ 
    super.onListItemClick(l, v, position, id); 
    Intent i = new Intent(this, AddTimeEntry.class); /// fix this back to wha tit was 
    i.putExtra(DatabaseStore.kEY_ROWID, id); 
    startActivityForResult(i, ACTIVITY_EDIT); 

} 

editinfo_tow.xml上面的帽子代碼和我得到空指針異常?

+0

可以使用切換按鈕? – Shrikant

+0

非常感謝我從來沒有新的內置到Android ..我只需要現在看它,看看如何去做 – Michael

+0

我在做類似的東西這裏! http://stackoverflow.com/questions/13523350/android-alarm-clock-ui – toobsco42

回答

0

您可以使用切換按鈕如下:

<LinearLayout 
         android:id="@+id/prob1" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" > 

         <TextView 
          android:layout_width="0dp" 
          android:layout_height="wrap_content" 
          android:layout_weight="4" 
          android:gravity="left|center" 
          android:text="@string/someText" 
          android:textColor="@color/lbl_text_color" 
          android:textSize="25sp" > 
         </TextView> 

         <ToggleButton 
          android:id="@+id/toggle" 
          android:layout_width="0dp" 
          android:layout_height="wrap_content" 
          android:layout_gravity="center|center_vertical" 
          android:layout_weight="1" 
          android:background="@drawable/toggle_no_img" 
          android:onClick="onToggleClick" 
          android:textOff="" 
          android:textOn="" /> 
        </LinearLayout> 
+0

顯示的每個條目將有toogle按鈕和以上,當我點擊我使用onListItemClick的條目之一,它得到的ID,這是傳入新的哪個條目是點擊,但我如何獲得ID,當我點擊toogle按鈕來知道哪一個被點擊? – Michael

+0

是否有可能使用tgButton.isChecked()方法而不是onListItemClick,因爲這是用戶將點擊n而不是整個listitem(我希望如此)的按鈕? – Shrikant

+0

我得到空指針例外...我添加了代碼給我的詭計 – Michael