我有这样的布局:每一行都是可点击的
---------------------------
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
---------------------------------------
这是我的代码:
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);
}
编辑info_tow.xml
<?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();
}
});
}
我使用了上面的代码,我得到空指针异常?