Click here to Skip to main content
15,894,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
assume i have 4 groups, each group have 4 childs => i have 16 childs, now i want like this, when i click on a child, it's appear drawableleft (or image view), and if after i click another child, the drawableleft appear on this child and disappear on previous child, that means, it only appaer a drawable left ( much like radio button), thanks 4 your help, ineed urgently, here my snippet code:


child.xml:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android">xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="40dp"
android:removed="@drawable/e"
android:clickable="true"
android:orientation="vertical"
android:paddingLeft="1dp"
tools:context=".MainActivity" >

<linearlayout> android:layout_width="match_parent"
android:layout_height="39dp"
android:gravity="center_vertical" >

<ImageView
android:id="@+id/childImage"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_margin="5dp"
android:background="@drawable/i"
android:contentDescription="@string/hello_world"
android:visibility="invisible" />

<checkedtextview>
android:id="@+id/textView1"
android:layout_width="wrap_removed"
android:layout_height="wrap_removed"
android:layout_marginLeft="5dp"
android:text="@string/hello_world"
android:textColor="@color/tcl"
android:textSize="14sp"
android:textStyle="bold"
android:drawableLeft="@drawable/pm2" />
pm2.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/i" xmlns:android="#unknown">
android:state_selected="true"
/>

</selector>

adapter.java
public View getChildView(final int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
tempChild = (ArrayList<ObjectTemp>) Childtem.get(groupPosition);
final helperuti he;
if (convertView == null) {
he=new helperuti();
convertView = minflater.inflate(R.layout.childrow, null);
he.tv=(CheckedTextView) convertView.findViewById(R.id.textView1);
he.imv=(ImageView) convertView.findViewById(R.id.childImage);

convertView.setTag(he);
}else{
he=(helperuti) convertView.getTag();
}

he.tv.setText(tempChild.get(childPosition).getTvTitle());
CheckedTextView[] ct; boolean b=he.tv.isSelected();

if(b){

he.imv.setVisibility(ImageView.VISIBLE);
}
else{
he.imv.setVisibility(ImageView.INVISIBLE);
}

final int caox=groupItem.size() * Childtem.size();
convertView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub

he.tv.setSelected(!he.tv.isSelected());
notifyDataSetChanged();
}
});
return convertView;
}

public class helperuti{
CheckedTextView tv;
ImageView imv;
}

public void setselc(int selc){
this.selc=selc;
notifyDataSetChanged();
}


mainactivity.java

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ExpandableListView expandbleLis = getExpandableListView();
expandbleLis.setDividerHeight(2);
expandbleLis.setGroupIndicator(null);
expandbleLis.setClickable(true);
getExpandableListView().setTextFilterEnabled(true);
getExpandableListView().setChoiceMode(ExpandableListView.CHOICE_MODE_SINGLE);

getExpandableListView().setItemChecked(0, true);

setGroupData();
setChildGroupData();

final NewAdapter mNewAdapter = new NewAdapter(groupItem, childItem);
mNewAdapter
.setInflater(
(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE),
this);
getExpandableListView().setAdapter(mNewAdapter);
expandbleLis.setOnChildClickListener(new OnChildClickListener() {

@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
// TODO Auto-generated method stub
mNewAdapter.setselc(childPosition);
getExpandableListView().setItemChecked(childPosition, true);
return true;
}`
});
}


who need link down project can pm me gmail: coldprince10@gmail.com
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900