2017-11-11 174 views
0

我一直在做一個項目,我需要標記出席員工並將其存儲在數據庫中。爲此,我在收音機組中實施單選按鈕,以確定是否存在員工缺席或半天假......要做到這一點,我必須從列表視圖中獲得這些值,並點擊完成按鈕出席必須標記並存儲在數據庫中。從我的自定義列表視圖中處理這些數據的那些單選按鈕的值!! ??如何處理列表視圖上的單選按鈕值

我的自定義列表適配器代碼

public class CustomCalendarAdapter extends ArrayAdapter<String> { 

private final Activity context; 
private final String[] itemname; 
private final Bitmap[] imgid; 

public CustomCalendarAdapter(Activity context, String[] itemname, Bitmap[] imgid) { 
    super(context, R.layout.list_item2, itemname); 

    this.context=context; 
    this.itemname=itemname; 
    this.imgid=imgid; 
} 

@Nonnull 
public View getView(int position, View view,@Nonnull ViewGroup parent) { 
    LayoutInflater inflater=context.getLayoutInflater(); 
    View rowView=inflater.inflate(R.layout.list_item2, null,true); 

    TextView txtTitle = (TextView) rowView.findViewById(R.id.item); 
    ImageView imageView = (ImageView) rowView.findViewById(R.id.icon); 
    TextView extratxt = (TextView) rowView.findViewById(R.id.textView1); 
    final RadioButton rb1 = (RadioButton) rowView.findViewById(R.id.rb1); 
    final RadioButton rb2 = (RadioButton) rowView.findViewById(R.id.rb2); 
    final RadioButton rb3 = (RadioButton) rowView.findViewById(R.id.rb3); 

    rb2.setChecked(true); 
    txtTitle.setText(itemname[position]); 
    imageView.setImageBitmap(imgid[position]); 
    extratxt.setText("Description "+itemname[position]); 

    return rowView; 

} } 

我的列表視圖XML代碼

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="horizontal" android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<ImageView 
    android:id="@+id/icon" 
    android:layout_width="80dp" 
    android:layout_height="80dp" 
    android:background="@drawable/rowselector" 
    android:padding="5dp" /> 

<LinearLayout android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:minHeight="80dp" 
    android:layout_weight="1" 
    android:background="@drawable/rowselector" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/item" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Medium Text" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:layout_marginLeft="10dp" 
     android:layout_marginTop="15dp" 
     android:padding="2dp" 
     android:textColor="#000" /> 
    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="TextView" 
     android:layout_marginLeft="10dp"/> 

</LinearLayout> 

<RadioGroup 
    android:id="@+id/rg" 
    android:orientation="horizontal" 
    android:layout_marginTop="25dp" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <RadioButton 
     android:id="@+id/rb1" 
     android:text="P" 
     android:padding="2dp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
    <RadioButton 
     android:id="@+id/rb2" 
     android:text="A" 
     android:padding="2dp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
    <RadioButton 
     android:id="@+id/rb3" 
     android:text="HD" 
     android:padding="2dp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

</RadioGroup> 

我與列表視圖活動代碼中,我要顯示列表和處理DONE按鈕

public class Attendance extends AppCompatActivity { 

CustomCalendarAdapter adapter; 
ArrayList<String> strings = new ArrayList<>(); 
ArrayList<Bitmap> bitmaps = new ArrayList<>(); 
ListView lv; 

    @Override 
     protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_attendance); 

    lv = (ListView) findViewById(R.id.list); 

    myinfodbhelper mDbHelper = new myinfodbhelper(this); 
    SQLiteDatabase db = mDbHelper.getReadableDatabase(); 

    Cursor cursor = db.rawQuery("SELECT * FROM " 
      + myinfocontract.myinfoentry.TABLE_NAME,null); 

    while (cursor.moveToNext()) { 
     String currentfname = cursor.getString(cursor.getColumnIndex("name")); 
     byte[] bytes = cursor.getBlob(cursor.getColumnIndex("image")); 
     Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); 

     strings.add(currentfname); 
     bitmaps.add(bitmap); 
    } 
    cursor.close(); 

    String[] itemname = strings.toArray(new String[0]); 
    Bitmap[] imageid = bitmaps.toArray(new Bitmap[0]); 
    adapter = new CustomCalendarAdapter(this, itemname, imageid); 
    lv.setAdapter(adapter); 
    lv.setEmptyView(tv); 

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.floatingActionButton); 
    fab.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      //Here I want to handle the radio button check 
      //And mark done by the floatingActionButton id in my listview xml file 
     } 
    }); 

如果這個問題已經回答plz提供鏈接

我找不到相關的解決方案,我的問題,因此我問這個問題......必須做什麼修改?

THX提前...

回答

1

步驟1

創建一個Bean類的Y我們的數據用整數變量attendance_type。並將這些數據的列表傳遞給您的適配器。

步驟2

設置點擊收聽你的廣播集團。並設置attendance_type(無論選擇)回到無線電檢查更改爲列表並更改它在數據庫中。

步驟3

現在每次更改考勤時間,你將有一個更新列表。

相關問題