1

我有一个 tablelayout xml 文件,它将 sqlite 数据库中的元素显示为表格格式。我想要的是能够有一个警报对话框或弹出窗口,这样当我单击一个按钮时,它会将复选框检查状态更改为该特定行的真实状态。这是我的 xml 文件(events.xml)

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/table_layout"
    android:stretchColumns="*"
    android:background="#EA6D11">

     <TableRow  
        android:id="@+id/table_row"
        android:background="#B18C58"
        android:layout_margin="2dp">

      <!-- Column 1 -->
      <TextView
         android:id="@+id/eventId"
         android:layout_width="0dip"
         android:layout_height="wrap_content"
         android:padding="5dip"       
         android:textStyle="bold"
         android:textAllCaps="true"
         android:textColor="#00FF00"
         android:layout_margin="1dip"
         android:layout_weight="0.5"
         android:text="Column 0.5" />       

      <!-- Column 2 -->
      <TextView
         android:id="@+id/eventName"
         android:layout_width="0dip"
         android:layout_height="wrap_content"
         android:padding="5dip"
         android:textStyle="bold"
         android:textAllCaps="true"
         android:textColor="#FFFFFF"
         android:layout_margin="4dip"
         android:layout_weight="0.8"
         android:text="Column 2" />  

      <!-- Column 3 -->
      <TextView
         android:id="@+id/eventRecordName"
         android:layout_width="0dip"
         android:layout_height="wrap_content"
         android:padding="5dip"
         android:textColor="#FFFFFF"
         android:textAllCaps="true"
         android:textStyle="bold"
         android:layout_margin="4dip"
         android:layout_weight="0.8"
         android:text="Column 3" />
    <!-- Column 4 -->   
    <CheckBox
        android:id="@+id/checkbox"
        android:checked="false"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:clickable="false"
        android:layout_margin="1dp"
        android:layout_weight="0.3"
        android:button="@drawable/checkbox"/>
        </TableRow> 

</TableLayout>

这就是我在我的活动课程中实现的。

public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    dbAdapter = new dbHelperAdapter(this); 
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);       
    Cursor eventListCursor = dbAdapter.fetchAllEvents();
    startManagingCursor(eventListCursor);        
    String[] from = new String[] {dbHelperAdapter.EVENT_ID, dbHelperAdapter.EVENT_NAME, dbHelperAdapter.EVENT_rNAME};
    int[] target = new int[]{R.id.eventId, R.id.eventName, R.id.eventRecordName};
    cursorAdapter = new SimpleCursorAdapter(this, R.layout.event_row_def, eventListCursor, from, target);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);
    setListAdapter(cursorAdapter); 
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);
    ListView lv = getListView();
    lv.setOnItemLongClickListener(new OnItemLongClickListener(){

        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            lv.requestFocus();
            showPopup();
            return true;
        }

    });
}

这是 showPopup() 方法。

        public void showPopup(){
        final AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setTitle("EVENT");
        alert.setMessage("RollCall");       
        alert.setPositiveButton("MARK-EVENT", new DialogInterface.OnClickListener(){

        @Override    
        public void onClick(DialogInterface dialog, int which){
          //change checkbox checked state = true once clicked and move to next row
        }

    });

        alert.setNeutralButton("CLOSE", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                //require some actiion here once button is clicked
            }
        });
        AlertDialog alertDialog = alert.create();
        alertDialog.show();

    }

提前感谢您认为适合此实施的任何想法。

4

0 回答 0