how can check answers ? i have error with this method
public class exam_1_program extends Activity {
private ListView listview;
private CheckBox check1;
private CheckBox check2;
private CheckBox check3;
private CheckBox check4;
public static final String[] Queshion_txt = new String[] { "سوال 1",
"سوال 2", "سوال 3", "سوال 4", "سوال 5" };
public static final String[] check_itam_1 = new String[] { "تست یک",
"تست یک سوال دو",
"تست یک سوال سه ", "تست یک سوال چهار", "تست یک سوال پنج"
};
public static final String[] check_itam_2 = new String[] { "تست دو",
"تست دو سوال دو", "تست دو سوال سه", "تست دو سوال چهار",
"تست دو سوال پنج"
};
public static final String[] check_itam_3 = new String[] { "تست سه",
"تست دو سال سه", "تست سه سوال سه", "تست چهار سوال سه",
"تست پنج سوال سه"
};
public static final String[] check_itam_4 = new String[] { "تست چهار",
"تست دو سوال چهار", "سوال سه", "سوال چهار", "سوال پنج"
};
List<itam_row_adapter_exam> rowItems;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.exam_1);
check1 = (CheckBox) findViewById(R.id.item_1);
check2 = (CheckBox) findViewById(R.id.item_2);
check3 = (CheckBox) findViewById(R.id.item_3);
check4 = (CheckBox) findViewById(R.id.item_4);
rowItems = new ArrayList<itam_row_adapter_exam>();
for (int i = 0; i < Queshion_txt.length; i++) {
itam_row_adapter_exam item = new itam_row_adapter_exam(
Queshion_txt[i], check_itam_1[i], check_itam_2[i],
check_itam_3[i], check_itam_4[i]);
rowItems.add(item);
}
listview = (ListView) findViewById(R.id.listview_exam);
BaseAdapter_exam adapter = new BaseAdapter_exam(this, rowItems);
listview.setAdapter(adapter);
check1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (((CheckBox) v).isChecked()) {
Toast.makeText(getApplicationContext(),"Bro, try Android :)", Toast.LENGTH_LONG).show();
}
}
});
// if (check1) {
//
// Toast.makeText(getApplicationContext(),"This is an Android Toast Message",
// Toast.LENGTH_LONG).show();
//
// }
}
}
public class BaseAdapter_exam extends BaseAdapter {
Context context;
private List<itam_row_adapter_exam> rowItems;
public BaseAdapter_exam(Context context, List<itam_row_adapter_exam> items) {
this.context = context;
this.rowItems = items;
}
private class ViewHolder_exam {
TextView txtQueshion;
CheckBox check1;
CheckBox check2;
CheckBox check3;
CheckBox check4;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return rowItems.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return rowItems.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return rowItems.indexOf(getItem(position));
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder_exam holder = null;
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
{
convertView = mInflater.inflate(R.layout.question, null);
holder = new ViewHolder_exam();
holder.txtQueshion = (TextView) convertView.findViewById(R.id.textView1);
holder.check1 = (CheckBox) convertView.findViewById(R.id.item_1);
holder.check2 = (CheckBox) convertView.findViewById(R.id.item_2);
holder.check3 = (CheckBox) convertView.findViewById(R.id.item_3);
holder.check4 = (CheckBox) convertView.findViewById(R.id.item_4);
convertView.setTag(holder);
} else
{
holder = (ViewHolder_exam) convertView.getTag();
}
itam_row_adapter_exam rowItem = (itam_row_adapter_exam) getItem(position);
holder.txtQueshion.setText(rowItem.getquetion());
holder.check1.setText(rowItem.getcheck1());
holder.check2.setText(rowItem.getcheck2());
holder.check3.setText(rowItem.getcheck3());
holder.check4.setText(rowItem.getcheck4());
return convertView;
}
}
package adapter_view;
public class itam_row_adapter_exam {
private String quetion = "";
private String check1 = "";
private String check2 = "";
private String check3 = "";
private String check4 = "";
public itam_row_adapter_exam(String quetion, String check1, String check2,
String check3, String check4) {
this.quetion = quetion;
this.check1 = check1;
this.check2 = check2;
this.check3 = check3;
this.check4 = check4;
}
//
public String getquetion() {
return quetion;
}
public void setquetion(String quetion) {
this.quetion = quetion;
}
//
public String getcheck1() {
return check1;
}
public void setchechk1(String check1) {
this.check1 = check1;
}
//
public String getcheck2() {
return check2;
}
public void setchechk2(String check2) {
this.check2 = check2;
}
//
public String getcheck3() {
return check3;
}
public void setchechk3(String check3) {
this.check3 = check3;
}
//
public String getcheck4() {
return check4;
}
public void setchechk4(String check4) {
this.check4 = check4;
}
//
}
Aucun commentaire:
Enregistrer un commentaire