0
확인란에 문제가 있습니다. 사용자가 자식을 클릭하면, 응용 프로그램은 자식 사용자가 클릭 한 토스트 메시지를 표시해야합니다. 그것은 아이의 textview를 클릭하면 잘 작동하지만, 내가 체크 박스를 클릭하면 아무것도 할아버지. 또한 하위 항목을 클릭하면 내 체크 박스 상태가 변경되기를 원합니다. 내가 볼 수없는 것을 본다. 다음은 주요 활동 여기exapndablelistview (android) 하위의 CheckBox
private ExpandableAdapter adapter; private ExpandableListView expandableList; private List<Pitanja> pitanjas = new ArrayList<Pitanja>(); private ArrayList<Pitanja> listaPitanja = new ArrayList<Pitanja>(); private List<Odgovor> odgovors = new ArrayList<Odgovor>(); public static HashMap<Integer, Integer> pitanjaa; private Intent intent; private ProgressDialog pDialog; private TextView output; private List<Ispit> ispitList; private String pozicija; private Button posalji;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ispit);
output = (TextView) findViewById(R.id.ispit_datum);
output.setMovementMethod(new ScrollingMovementMethod());
pitanjaa = new HashMap<Integer, Integer>();
posalji = (Button) findViewById(R.id.posaljiIspitButton);
posalji.setOnClickListener(this);
generateData();
initEx();
intent = getIntent();
RequestPackage p = new RequestPackage();
p.setUri("http://arka.foi.hr/WebDiP/2012_projekti/WebDiP2012_085/AIR/ispit.php");
p.setMethod("POST");
p.setParam("id_kolegij", intent.getStringExtra("id_predmeta"));
Log.i("Saljem podatke ", intent.getStringExtra("id_predmeta"));
MyTask task = new MyTask();
task.execute(p);
}
private void updateDisplay(){
Collections.shuffle(ispitList);
output.setText(String.valueOf(ispitList.get(0).getId()));
MyRequest task = new MyRequest();//this works fine
RequestPackage r = new RequestPackage();//works
r.setMethod("POST");//works
r.setUri("http://arka.foi.hr/WebDiP/2012_projekti/WebDiP2012_085/AIR/pitanja.php");//works
r.setParam("id_kolegij", output.getText().toString());//works
task.execute(r);
}
private void initEx(){
adapter = new ExpandableAdapter(IspitActivity.this, listaPitanja);
expandableList = (ExpandableListView) findViewById(R.id.expandableIspitListView);
expandableList.setAdapter(adapter);
for (int i=0;i<adapter.getGroupCount();i++){
expandableList.collapseGroup(i);
}
expandableList.setOnChildClickListener(new OnChildClickListener(){
@Override
public boolean onChildClick(ExpandableListView arg0, View arg1,
int arg2, int arg3, long arg4) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Klikno si na " + adapter.getChild(arg2, arg3).getText() + " " + adapter.getChild(arg2, arg3).getTocan_netocan(), Toast.LENGTH_SHORT).show();
if (Integer.parseInt(adapter.getChild(arg2, arg3).getTocan_netocan()) == 0)
pitanjaa.put(arg2, arg3);
Log.i("pitanja koja si odgovorio su", pitanjaa.toString());
adapter.getChild(arg2, arg3).setSelected(true);
return true;
}
});
}
private void generateData(){
Pitanja p;
for (int i=0;i<pitanjas.size();i++){
ArrayList<Odgovor> od = new ArrayList<Odgovor>();
for (int z=0;z<odgovors.size();z++){
if (odgovors.get(z).getId_pitanja().contains(String.valueOf(pitanjas.get(i).getId()))){
od.add(odgovors.get(z));
}
}
pozicija = pitanjas.get(i).getText();
p = new Pitanja(i, pozicija, od);
listaPitanja.add(p);
}
}
private class MyTask extends AsyncTask<RequestPackage, String, List<Ispit>>{
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(IspitActivity.this);
pDialog.setMessage("Dobavljam podatke...");
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected List<Ispit> doInBackground(RequestPackage... params) {
String content = HttpManager.getData(params[0]);
ispitList = JSONParser.parseIspit(content.substring(1, content.length()-1));
Log.i("Parsirano izgleda sljedeci", content.substring(1, content.length()-1));
return ispitList;
}
@Override
protected void onPostExecute(List<Ispit> result) {
super.onPostExecute(result);
pDialog.dismiss();
updateDisplay();
}
}
@Override
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(), PregledActivity.class);
startActivity(intent);
}
}
내 코드 내 expandablelistview 어댑터
public class ExpandableAdapter extends BaseExpandableListAdapter{ LayoutInflater inflater; private List<Pitanja> groups; public ExpandableAdapter(Context context,List<Pitanja> groups) { super(); this.groups=groups; inflater= (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } public void addItem(Odgovor child,Pitanja group) { if(!groups.contains(group)) { groups.add(group); } int index=groups.indexOf(group); ArrayList<Odgovor> ch=groups.get(index).getOdgovors(); ch.add(child); groups.get(index).setOdgovors(ch); } public Odgovor getChild(int groupPosition, int childPosition) { ArrayList<Odgovor> ch=groups.get(groupPosition).getOdgovors(); return ch.get(childPosition); } public long getChildId(int groupPosition, int childPosition) { return childPosition; } @Override public int getChildrenCount(int groupPosition) { ArrayList<Odgovor> ch=groups.get(groupPosition).getOdgovors(); return ch.size(); } public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { Odgovor child= (Odgovor) getChild(groupPosition,childPosition); TextView childName=null; CheckBox cb = null; if(convertView==null) { convertView=inflater.inflate(R.layout.child_item, null); } childName=(TextView) convertView.findViewById(R.id.textview_child_item); childName.setText(child.getText()); cb = (CheckBox) convertView.findViewById(R.id.checkbox_child_item); if (child.isSelected()) cb.setChecked(true); return convertView; } public Pitanja getGroup(int groupPosition) { return groups.get(groupPosition); } public int getGroupCount() { return groups.size(); } public long getGroupId(int groupPosition) { return groupPosition; } public View getGroupView(final int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { TextView groupName = null; Pitanja group=(Pitanja) getGroup(groupPosition); if(convertView==null) { convertView=inflater.inflate(R.layout.parent_item, null); } groupName=(TextView) convertView.findViewById(R.id.parent_item); groupName.setText(group.getText()); return convertView; } public boolean isChildSelectable(int groupPosition, int childPosition) { return true; } public boolean hasStableIds() { return true; } }
내 아이 뷰입니다
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <CheckBox android:id="@+id/checkbox_child_item" android:layout_width="wrap_content" android:layout_height="wrap_content" android:focusable="false" /> <TextView android:id="@+id/textview_child_item" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>
내 체크 박스에 초점을 맞춘다면 너무 효과적이지 않습니다. 누군가가 아이디어를 가지고 있습니다