当我向下移动时滚动窗口小部件刷新。我需要停止刷新
我什么时候向下移动滚动小部件刷新。我需要停止刷新。小部件的价值保持不变直到图像按钮被点击。
更改小部件的值后,我向下滚动小部件值后重置。当我执行行动时,这些值应该保留
this is refreshing widgets
XML文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginBottom="30dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="30dp"
android:textColor="#000"
>
<TextView
android:id="@+id/text_Lt"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:gravity="center"
android:textAlignment="center"
android:textColor="#000"
android:layout_marginTop="2.5dp"
android:layout_marginBottom="2.5dp"
/>
<LinearLayout
android:id="@+id/Teacher_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:orientation="vertical"
android:textColor="#000"
>
<TextView
android:id="@+id/text_teacher_name"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:textColor="#000"
android:layout_marginTop="10dp"
/>
<Spinner
android:id="@+id/spinner_teacher_name"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginTop="-20dp">
</Spinner>
</LinearLayout>
<LinearLayout
android:id="@+id/radioButtons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="vertical">
<RadioGroup
android:id="@+id/radioButton_group_PresentAbsent"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/radioButton_present"
android:layout_width="80dp"
android:layout_height="25dp"
android:text="Present"
android:textSize="12sp"
/>
<RadioButton
android:layout_marginTop="3dp"
android:id="@+id/radioButton_absent"
android:layout_width="80dp"
android:layout_height="25dp"
android:text="Absent"
android:textSize="12sp"
/>
</RadioGroup>
</LinearLayout>
<EditText
android:id="@+id/etxtStartTimePicker"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:textSize="11sp"
android:text="LATE"
android:layout_marginTop="2.5dp"
android:layout_marginBottom="2.5dp"/>
<EditText
android:id="@+id/etxtEndTimePicker"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:textSize="11sp"
android:text="LEAVE"
android:layout_marginTop="2.5dp"
android:layout_marginBottom="2.5dp"
android:visibility="invisible"
/>
<ImageButton
android:id="@+id/submit_Attendance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:layout_marginLeft="5dp"
android:layout_marginTop="2.5dp"
android:layout_marginBottom="2.5dp"
android:src="@drawable/biit"
android:visibility="visible"/>
</LinearLayout>
更改小部件的值后,当我向下滚动小部件值重置后,请帮助。这些值应该在我执行操作时保留。
Java文件
public class CustomAdapter extends BaseAdapter
{
private static LayoutInflater inflater = null;
String[] class_room;
Context context;
String[] teacher_name;
String[] days;
ArrayAdapter<String> arrayAdapter1;
Calendar c = Calendar.getInstance();
public CustomAdapter(teacher_attendance mainActivity, String[] arr, String[] arr1, String[] arr2) {
// TODO Auto-generated constructor stub
class_room = arr;
teacher_name = arr1;
days=arr2;
context = mainActivity;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
// TODO Auto-generated method stub
return class_room.length
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
final Holder holder = new Holder();
final View rowView;
rowView = inflater.inflate(R.layout.row_layout, null);
holder.radioButton_Group_PresentAbsent = (RadioGroup) rowView.findViewById(R.id.radioButton_group_PresentAbsent);
holder.radioButtonPresent = (RadioButton) rowView.findViewById(R.id.radioButton_present);
holder.txtlt = (TextView) rowView.findViewById(R.id.text_Lt);
holder.txtteacher = (TextView) rowView.findViewById(R.id.text_teacher_name);
holder.radioButtonAbsent = (RadioButton) rowView.findViewById(R.id.radioButton_absent);
holder.etxtStart_time_Picker = (EditText) rowView.findViewById(R.id.etxtStartTimePicker);
holder.etxtStart_time_Picker.setFocusable(false);
holder.etxtEnd_time_Picker = (EditText) rowView.findViewById(R.id.etxtEndTimePicker);
holder.etxtEnd_time_Picker.setFocusable(false);
holder.txtlt.setText(class_room[position]);
holder.txtteacher.setText(teacher_name[position]);
holder.submitAttendance = (ImageButton) rowView.findViewById(R.id.submit_Attendance);
holder.submitAttendance.setVisibility(View.VISIBLE);
holder.spinner_teacher_name = (Spinner) rowView.findViewById(R.id.spinner_teacher_name);
arrayAdapter1 = new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item, teacher_name);
arrayAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
holder.spinner_teacher_name.setAdapter(arrayAdapter1);
holder.submitAttendance.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String teacherName, status = null, startTime, endTime;
holder.dataBaseHelper = new DataBaseHelper(v.getContext());
startTime = holder.etxtStart_time_Picker.getText().toString();
endTime = holder.etxtEnd_time_Picker.getText().toString();
teacherName = holder.txtteacher.getText().toString();
if (holder.radioButtonPresent.isChecked()) {
status = holder.radioButtonPresent.getText().toString();
holder.dataBaseHelper.insertData(teacherName, status, startTime, endTime);
Toast.makeText(rowView.getContext(), teacher_name[position] + " is " + status, Toast.LENGTH_SHORT).show();
} else if (holder.radioButtonAbsent.isChecked()) {
status = holder.radioButtonAbsent.getText().toString();
holder.dataBaseHelper.insertData(teacherName, status, startTime, endTime);
Toast.makeText(rowView.getContext(), teacher_name[position] + " is " + status, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(rowView.getContext(), "Teacher Status is not Mark", Toast.LENGTH_SHORT).show();
}
}
});
holder.spinner_teacher_name.setVisibility(View.INVISIBLE);
holder.txtteacher.setVisibility(View.VISIBLE);
holder.spinner_teacher_name.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
for (int a = 0; a < position; a++) {
holder.txtteacher.setText(teacher_name[position]);
holder.spinner_teacher_name.setVisibility(View.INVISIBLE);
holder.txtteacher.setVisibility(View.VISIBLE);
holder.radioButtonPresent.setChecked(true);
holder.etxtEnd_time_Picker.setVisibility(View.VISIBLE);
holder.etxtStart_time_Picker.setVisibility(View.VISIBLE);
}
}
public void onNothingSelected(AdapterView<?> parent) {
}
});
holder.etxtStart_time_Picker.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
TimePickerDialog.OnTimeSetListener tim = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// TODO Auto-generated method stub
holder.etxtStart_time_Picker.setText(hourOfDay + " : " + minute);
}
};
new TimePickerDialog(context, tim, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), true).show();
holder.etxtEnd_time_Picker.setVisibility(View.VISIBLE);
}
});
holder.etxtEnd_time_Picker.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
TimePickerDialog.OnTimeSetListener tim = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
holder.etxtEnd_time_Picker.setText(hourOfDay + " : " + minute);
}
};
new TimePickerDialog(context, tim, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), true).show();
}
});
holder.radioButtonAbsent.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
if (holder.radioButtonAbsent.isChecked())
{
holder.etxtEnd_time_Picker.setVisibility(View.INVISIBLE);
holder.etxtStart_time_Picker.setVisibility(View.INVISIBLE);
holder.spinner_teacher_name.setVisibility(View.VISIBLE);
holder.txtteacher.setVisibility(View.INVISIBLE);
} else if (holder.radioButtonPresent.isChecked()) {
holder.etxtEnd_time_Picker.setVisibility(View.VISIBLE);
holder.etxtStart_time_Picker.setVisibility(View.VISIBLE);
holder.spinner_teacher_name.setVisibility(View.INVISIBLE);
holder.txtteacher.setVisibility(View.VISIBLE);
}
}
});
holder.radioButtonPresent.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
if (holder.radioButtonPresent.isChecked()) {
holder.etxtStart_time_Picker.setVisibility(View.VISIBLE);
holder.spinner_teacher_name.setVisibility(View.INVISIBLE);
holder.txtteacher.setVisibility(View.VISIBLE);
} else if (holder.radioButtonAbsent.isChecked()) {
holder.etxtStart_time_Picker.setVisibility(View.INVISIBLE);
holder.etxtEnd_time_Picker.setVisibility(View.INVISIBLE);
holder.spinner_teacher_name.setVisibility(View.VISIBLE);
holder.txtteacher.setVisibility(View.INVISIBLE);
}
}
});
return rowView;
}
public class Holder
{
TextView txtlt, txtteacher;
RadioButton radioButtonPresent, radioButtonAbsent;
EditText etxtStart_time_Picker,etxtEnd_time_Picker;
Spinner spinner_teacher_name, spinnerDays;
ImageButton submitAttendance;
RadioGroup radioButton_Group_PresentAbsent;
DataBaseHelper dataBaseHelper;
}
}
答案 0 :(得分:0)
我读了一篇博客,以获得我所遇到的问题的帮助。我想分享从我得到帮助的链接from this link
我得到了这个参考表格this link
这个类是CustomAdapter,它扩展了BaseAdapter
Holder holder = new Holder();
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
// TODO Auto-generated method stub
final View rowView;
convertView = inflater.inflate(R.layout.row_layout, null);
holder.radioButton_Group_PresentAbsent = (RadioGroup) convertView.findViewById(R.id.radioButton_group_PresentAbsent);
holder.radioButtonPresent = (RadioButton) convertView.findViewById(R.id.radioButton_present);
holder.txtlt = (TextView) convertView.findViewById(R.id.text_Lt);
holder.txtteacher = (TextView) convertView.findViewById(R.id.text_teacher_name);
holder.radioButtonAbsent = (RadioButton) convertView.findViewById(R.id.radioButton_absent);
holder.txtStart_time_Picker = (TextView) convertView.findViewById(R.id.txtStartTimePicker);
holder.txtStart_time_Picker.setFocusable(false);
holder.txtEnd_time_Picker = (TextView) convertView.findViewById(R.id.txtEndTimePicker);
holder.txtEnd_time_Picker.setFocusable(false);
holder.txtlt.setText(class_room[position]);
holder.txtteacher.setText(teacher_name[position]);
holder.submitAttendance = (ImageButton) convertView.findViewById(R.id.submit_Attendance);
holder.submitAttendance.setVisibility(View.VISIBLE);
holder.spinner_teacher_name = (Spinner) convertView.findViewById(R.id.spinner_teacher_name);
arrayAdapter1 = new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item, teacher_name);
arrayAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
holder.spinner_teacher_name.setAdapter(arrayAdapter1);
holder.submitAttendance.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String teacherName, status = null, startTime, endTime;
holder.dataBaseHelper = new DataBaseHelper(v.getContext());
startTime = holder.txtStart_time_Picker.getText().toString();
endTime = holder.txtEnd_time_Picker.getText().toString();
teacherName = holder.txtteacher.getText().toString();
DataBaseHelper ds = new DataBaseHelper(context);
if (holder.radioButtonPresent.isChecked()) {
status = holder.radioButtonPresent.getText().toString();
holder.dataBaseHelper.insertData(teacherName, status, startTime, endTime);
Toast.makeText(context, teacher_name[position] + " is " + status, Toast.LENGTH_SHORT).show();
} else if (holder.radioButtonAbsent.isChecked()) {
status = holder.radioButtonAbsent.getText().toString();
holder.dataBaseHelper.insertData(teacherName, status, startTime, endTime);
Toast.makeText(context, teacher_name[position] + " is " + status, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context, "Teacher Status is not Mark", Toast.LENGTH_SHORT).show();
}
}
});
holder.spinner_teacher_name.setVisibility(View.INVISIBLE);
holder.txtteacher.setVisibility(View.VISIBLE);
holder.spinner_teacher_name.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
for (int a = 0; a < position; a++) {
holder.txtteacher.setText(teacher_name[position]);
holder.spinner_teacher_name.setVisibility(View.INVISIBLE);
holder.txtteacher.setVisibility(View.VISIBLE);
holder.radioButtonPresent.setChecked(true);
holder.txtEnd_time_Picker.setVisibility(View.VISIBLE);
holder.txtStart_time_Picker.setVisibility(View.VISIBLE);
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
holder.txtStart_time_Picker.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
TimePickerDialog.OnTimeSetListener tim = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// TODO Auto-generated method stub
holder.txtStart_time_Picker.setText(hourOfDay + " : " + minute);
}
};
new TimePickerDialog(context, tim, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), true).show();
holder.txtEnd_time_Picker.setVisibility(View.VISIBLE);
}
});
holder.txtEnd_time_Picker.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
TimePickerDialog.OnTimeSetListener tim = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// TODO Auto-generated method stub
holder.txtEnd_time_Picker.setText(hourOfDay + " : " + minute);
}
};
new TimePickerDialog(context, tim, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), true).show();
}
});
holder.radioButtonAbsent.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (holder.radioButtonAbsent.isChecked()) {
holder.txtEnd_time_Picker.setVisibility(View.INVISIBLE);
holder.txtStart_time_Picker.setVisibility(View.INVISIBLE);
holder.spinner_teacher_name.setVisibility(View.VISIBLE);
holder.txtteacher.setVisibility(View.INVISIBLE);
} else if (holder.radioButtonPresent.isChecked()) {
holder.txtEnd_time_Picker.setVisibility(View.VISIBLE);
holder.txtStart_time_Picker.setVisibility(View.VISIBLE);
holder.spinner_teacher_name.setVisibility(View.INVISIBLE);
holder.txtteacher.setVisibility(View.VISIBLE);
}
}
});
holder.radioButtonPresent.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (holder.radioButtonPresent.isChecked()) {
holder.txtStart_time_Picker.setVisibility(View.VISIBLE);
holder.spinner_teacher_name.setVisibility(View.INVISIBLE);
holder.txtteacher.setVisibility(View.VISIBLE);
} else if (holder.radioButtonAbsent.isChecked()) {
holder.txtStart_time_Picker.setVisibility(View.INVISIBLE);
holder.txtEnd_time_Picker.setVisibility(View.INVISIBLE);
holder.spinner_teacher_name.setVisibility(View.VISIBLE);
holder.txtteacher.setVisibility(View.INVISIBLE);
}
}
});
convertView.setTag(holder);
convertView.setTag(R.id.radioButton_group_PresentAbsent, holder.radioButton_Group_PresentAbsent);
convertView.setTag(R.id.radioButton_present, holder.radioButtonPresent);
convertView.setTag(R.id.text_Lt, holder.txtlt);
convertView.setTag(R.id.radioButton_present, holder.radioButtonPresent);
convertView.setTag(R.id.text_teacher_name, holder.txtteacher);
convertView.setTag(R.id.radioButton_absent, holder.radioButtonAbsent);
convertView.setTag(R.id.txtStartTimePicker, holder.txtStart_time_Picker);
convertView.setTag(R.id.txtEndTimePicker, holder.txtEnd_time_Picker);
convertView.setTag(R.id.submit_Attendance, holder.submitAttendance);
convertView.setTag(R.id.spinner_teacher_name, holder.spinner_teacher_name);
}
else
{
holder = (Holder) convertView.getTag();
}
holder.radioButtonPresent.setTag(position);
holder.radioButtonAbsent.setTag(position);
return convertView;
}
public class Holder
{
protected TextView txtlt, txtteacher;
RadioButton radioButtonPresent, radioButtonAbsent;
TextView txtStart_time_Picker,txtEnd_time_Picker;
Spinner spinner_teacher_name, spinnerDays;
ImageButton submitAttendance;
RadioGroup radioButton_Group_PresentAbsent;
DataBaseHelper dataBaseHelper;
}
我非常努力地获得这个解决方案我现在得到了我想在这个网站上分享因为我也从这个网站获得了很多解决方案。