0

Проблема с флажком. Когда пользователь нажимает на дочернее устройство, приложение должно показывать тост-сообщение, на которое нажал дочерний элемент. Он отлично работает, если я нажимаю на textview для ребенка, но когда я нажимаю на флажок, ничего не heppend. Также, когда я нажимаю на дочерний элемент, я хочу, чтобы мой флажок изменился. Вы видите то, чего я не вижу. Вот мой код основной деятельностиCheckBox у ребенка exapndablelistview (android)

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> 

Если я сфокусируюсь на моем флажке, он тоже не работает. У кого-то есть идея

ответ

0

CheckBox будет использовать событие щелчка, прежде чем передавать его на событие события ExpandableListView. Вам нужно будет вручную прикрепить прослушиватель кликов к CheckBox в методе getChildView(), если вы хотите увидеть эти события щелчка.

Смежные вопросы